Zurück   RR:Board > Computer > Programmierung & Entwicklung > Projekte / Codes

Software Anwendungen mit Source Code - Projekt Vorstellung und Entwicklung.
Antwort
 
Themen-Optionen Thema durchsuchen

[C/C++] - Spiel - Connect
Alt 27.02.2011, 01:04   # 1
Rushh0ur
Master of supply
rot rot rot rot 
Bewertung:
Rushh0ur hat 1000 bis 2499 PunkteRushh0ur hat 1000 bis 2499 PunkteRushh0ur hat 1000 bis 2499 PunkteRushh0ur hat 1000 bis 2499 PunkteRushh0ur hat 1000 bis 2499 PunkteRushh0ur hat 1000 bis 2499 PunkteRushh0ur hat 1000 bis 2499 PunkteRushh0ur hat 1000 bis 2499 PunkteRushh0ur hat 1000 bis 2499 PunkteRushh0ur hat 1000 bis 2499 Punkte
Registriert seit: Feb 2007
Internet: DSL2 32K
Beiträge: 1.279
Power: 22
Hallo Comunity,

ich möchte mein kleines Projekt vorstellen was heut sein Alpha-Stadium erreicht hat.
Die Grundidee basiert auf dem Wikiartikel Connect (game), es geht ganz einfach darum zwei Punkte mit einander zu verbinden und das möglichst schnell um viele Punkte zu ergatert bevor die Zeit abläuft.

Das Spiel ist in C++ Programmiert und mit Arbeitet mit der SFML 2D Engine v1.6, dh. zum compilieren des Sources wird diese auch benötigt.

Ein Screenshot noch:


Downloads:
Projekt Source [Visual Studio C++ 2008]
Projekt Binäris [Win 32/64]
(Binäris sind hier Verboten von daher gibts keine, wenn jemand trotzdem welche haben will kann er sie in diesem Forum, wo ich das ganze auch Vorstelle, hollen)

Und damit es nicht so leer ist ein Auszug der HighScoreManager Klasse:
HighscoreManager.h
Code:
//////////////////////////////////////////////////////////// // // Highscore Manager // Copyright (C) 2011 ѕυвZєяo // //////////////////////////////////////////////////////////// #ifndef _HIGHSCOREMANAGER_H_ #define _HIGHSCOREMANAGER_H_ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// #include "stdafx.h" //////////////////////////////////////////////////////////// /// Defines a simple higshcore entry /// with name and points of a player //////////////////////////////////////////////////////////// struct SHighscoreEntry { TCHAR name[16]; unsigned int points; }; //////////////////////////////////////////////////////////// /// CHighscoreManager provides an highscore manager /// to load and save higscores from and to a file, /// and also to read, add and clear entrys. //////////////////////////////////////////////////////////// class CHighscoreManager { public: //////////////////////////////////////////////////////////// /// Default constructor /// /// \param sFile: path to file for load and save data /// //////////////////////////////////////////////////////////// CHighscoreManager (const tstring &sFile); //////////////////////////////////////////////////////////// /// Default destructor /// //////////////////////////////////////////////////////////// ~CHighscoreManager (); //////////////////////////////////////////////////////////// /// Compute the count of entrys in list /// /// \return coutn of entrys /// //////////////////////////////////////////////////////////// int GetEntryCount (); //////////////////////////////////////////////////////////// /// Returns the Data of an entry /// /// \param idx: the entry index /// from 0 to GetEntryCount-1 /// \param name: stores the name of player to this /// \param points: stores the points of player to this /// \retrun true on success /// //////////////////////////////////////////////////////////// bool GetEntry (const int &idx, tstring &name, unsigned int &points); //////////////////////////////////////////////////////////// /// Check if a highscore is reached /// /// \param score the score to check /// \return rang if the given value is a new /// highscore, else 0 /// //////////////////////////////////////////////////////////// int CheckHighscore(const unsigned int score); //////////////////////////////////////////////////////////// /// Add a new highscore to list /// /// \param name the players name /// \param score the players score /// \return rang of player /// //////////////////////////////////////////////////////////// int AddHighscore(const tstring &name, const unsigned int score); //////////////////////////////////////////////////////////// /// Clear and reset the entry list /// //////////////////////////////////////////////////////////// void ClearList (); //////////////////////////////////////////////////////////// /// Determinate if an file was found and loaded /// /// \retrun true if loaded, else false /// //////////////////////////////////////////////////////////// bool Loaded (); //////////////////////////////////////////////////////////// /// Loads an another file /// /// \param sFile: path to file for load and save data /// \return true if loaded, else false /// //////////////////////////////////////////////////////////// bool LoadFile (const tstring &sFile); //////////////////////////////////////////////////////////// /// Saves data to file /// /// \param sFile: path to file for save data /// \return true on sccuess /// //////////////////////////////////////////////////////////// bool SaveFile (const tstring &sFile); //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// public: static const int MAXENTRYCOUNT = 10; //< Max entry count private: bool pbLoaded; //< Is a file loaded sucessfully tstring psFile; //< path to file for storage of data SHighscoreEntry plEntryList[MAXENTRYCOUNT]; //< name and points list }; #endif // _HIGHSCOREMANAGER_H_
HighscoreManager.cpp
Code:
//////////////////////////////////////////////////////////// // // Highscore Manager // Copyright (C) 2011 ѕυвZєяo // //////////////////////////////////////////////////////////// #include "HighscoreManager.h" /*************************************************************************************************/ CHighscoreManager::CHighscoreManager(const tstring &sFile) { this->ClearList(); this->LoadFile(sFile); } /*************************************************************************************************/ CHighscoreManager::~CHighscoreManager() { this->SaveFile(this->psFile); } /*************************************************************************************************/ int CHighscoreManager::GetEntryCount() { for (int i=0; i < this->MAXENTRYCOUNT; ++i) if (!this->plEntryList[i].name[0]) return (i+1); return 0; } /*************************************************************************************************/ bool CHighscoreManager::GetEntry(const int &idx, tstring &name, unsigned int &points) { if (idx < this->MAXENTRYCOUNT) { if (this->plEntryList[idx].name[0]) { name = tstring(this->plEntryList[idx].name, 32); points = this->plEntryList[idx].points; return true; } } return false; } /*************************************************************************************************/ int CHighscoreManager::CheckHighscore(const unsigned int score) { for (int i=0; i < this->MAXENTRYCOUNT; ++i) { if (this->plEntryList[i].name[0]) { if (this->plEntryList[i].points < score) return (i+1); } else return (i+1); } return 0; } /*************************************************************************************************/ int CHighscoreManager::AddHighscore(const tstring &name, const unsigned int score) { int rang = this->CheckHighscore(score); if (rang) { for(int i=this->MAXENTRYCOUNT-1; i >= rang; --i) this->plEntryList[i] = this->plEntryList[i-1]; int len = sizeof(TCHAR) * 32; if (int(name.length() * sizeof(TCHAR)) < len) len = int(name.length() * sizeof(TCHAR)); memcpy(this->plEntryList[rang-1].name, name.c_str(), len); this->plEntryList[rang-1].points = score; } return rang; } /*************************************************************************************************/ void CHighscoreManager::ClearList() { memset(this->plEntryList, 0, sizeof(this->plEntryList)); } /*************************************************************************************************/ bool CHighscoreManager::Loaded() { return this->pbLoaded; } /*************************************************************************************************/ bool CHighscoreManager::LoadFile(const tstring &sFile) { fstream file(sFile.c_str(), ios::in | ios::binary); if (!file.fail()) { char cMagicID[4]; unsigned int iCount; unsigned int iSize; // Get File Size file.seekg(0, ios::end); iSize = (unsigned int)file.tellg(); file.seekp(0); // Check Data file >> cMagicID; if (!memcmp(cMagicID, "CHL",3)) { file.read((char*)&iCount, sizeof(iCount)); if (iSize == 3 + sizeof(iCount) + sizeof(this->plEntryList)) { file.read((char*)&this->plEntryList, sizeof(this->plEntryList)); this->pbLoaded = true; } else this->pbLoaded = false; } else this->pbLoaded = false; } else this->pbLoaded = false; this->psFile = sFile; return this->pbLoaded; } /*************************************************************************************************/ bool CHighscoreManager::SaveFile(const tstring &sFile) { fstream file(sFile.c_str(), ios::out | ios::binary); if (!file.fail()) { int iMaxEntryCount = this->MAXENTRYCOUNT; file << "CHL"; file.write((char*)&iMaxEntryCount, sizeof(iMaxEntryCount)); file.write((char*)&this->plEntryList, sizeof(this->plEntryList)); return true; } return false; }
Da dies mein erstes Projekt, im Sinne eines (komplexeren) Spieles ist, wäre ich über Anregung, Kritik und Wünsche erfreut.
Und am Rande gesagt, es sind noch spezielle Objekt bei höheren Levels geplannt wie zusätzlich Zeit, Bomben und ja mal schauen evtl. kommt noch was dazu.

PS: Die Kommentare im Source sind auf Englisch und da mein Englisch nicht das Beste ist wahrscheinlich mit vielen Fehlern; Übung macht den Meister.

Mfg Rushh0ur


  Rushh0ur ist offline   Mit Zitat antworten
Antwort

RR:Board > Computer > Programmierung & Entwicklung > Projekte / Codes > [C/C++] - Spiel - Connect


Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir erlaubt, Anhänge anzufügen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

vB Code ist An.
Smileys sind An.
[IMG] Code ist An.
HTML-Code ist Aus.

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
serv u connect problem. huke11 Sicherheit & Datenschutz 16 29.11.2012 17:40
Google und Facebook: Friend Connect und Facebook Connect gestartet zwa3hnn Netzwelt News 0 05.12.2008 09:42
mysql_connect() [function.mysql-connect]: Can't connect to local MySQL diaS Webentwicklung 5 03.10.2008 09:49
FritzBox Connect White G Sicherheit & Datenschutz 4 21.04.2008 13:14
Sql Connect chvb Sicherheit & Datenschutz 6 16.05.2006 15:41



Alle Zeitangaben in WEZ +1. Es ist jetzt 18:17 Uhr.
vBulletin Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.