Vollständige Version anzeigen : [C/C++] Spiel - Connect


Rushh0ur
27.02.2011, 02:04

Hallo Comunity,

ich möchte mein kleines Projekt vorstellen was heut sein Alpha-Stadium erreicht hat.
Die Grundidee basiert auf dem Wikiartikel {bild-down: ;img809;imageshack~us/img809/4990/screenwv;jpg}


Downloads:
Projekt Source (';;;xup~in/dl,19873877/connect_src_110227;rar/') [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 (;;;easy-coding~de/projektvorstellung-spiel-connect-t8962;html), wo ich das ganze auch Vorstelle, hollen)

Und damit es nicht so leer ist ein Auszug der HighScoreManager Klasse:
HighscoreManager;h

////////////////////////////////////////////////////////////
//
// 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

////////////////////////////////////////////////////////////
//
// 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

Hardware Preisvergleich | Amazon Blitzangebote!

Videos zum Thema
Video Loading...
Ähnliche Themen zu [C/C++] Spiel - Connect
  • Sft-Encrypter - Connect
    Hi leute habn problem beim uppen: die dateien sind aufn server drauf, nun will ich eine Sft-datei erstellen. Welche Adresse gehört denn genau in den SFT-Encrypter? Habe einfach nen server von der Pub-section ausgesucht, und darauf was geuppt. Ich habe also nur eine einfache IP: [...]

  • Sql Connect
    Original von w!ns0ck bei meiner sql-exec version (im showcase) wird ein genauerer fehler angezeigt SQL_ERROR kann nämlich viel bedeuten und wem zum geier soll helfen was du für sqltools hast ? ich erkenne darin keine hilfe es sei den du postest dein tool mfg moep [...]

  • mysql_connect() [function.mysql-connect]: Can't connect to local MySQL
    heyho, und zwar kommt bei mir immer der fehler... Warning: mysql_connect() [function;mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld;sock' (2) in /home/webpages/lima-city/dias1234/html/index;php on line 22 Kann nicht mit DB verbinden: Can't connect to loc [...]

  • Google und Facebook: Friend Connect und Facebook Connect gestartet
    Google und Facebook: Friend Connect und Facebook Connect gestartet Seit der Ankündigung über die neuen Vorhaben der beiden Internetunternehmen ist nunmehr ein halbes Jahr vergangen. Damals gaben die führenden Anbieter von sozialen Netzwerken ihre neusten Pläne für die weitere Zukunft bekannt. [...]



raid-rush.ws | Imprint & Contact pr