2010-04-05 23:38:59 +02:00
|
|
|
#ifndef _MODEL_H
|
|
|
|
#define _MODEL_H
|
|
|
|
|
|
|
|
#include "ModelBase.h"
|
|
|
|
#include "AsteroidsEnums.h"
|
|
|
|
|
|
|
|
namespace asteroids {
|
|
|
|
|
|
|
|
class Model : public Engine::ModelBase {
|
|
|
|
public:
|
2010-04-14 22:01:45 +02:00
|
|
|
virtual ~Model() {};
|
2010-04-05 23:38:59 +02:00
|
|
|
virtual void Process();
|
2010-11-27 20:56:38 +01:00
|
|
|
virtual void SetGameState (const unsigned int &state);
|
|
|
|
float GetWorldWidth ();
|
|
|
|
float GetWorldHeight ();
|
|
|
|
|
|
|
|
/* Event handler */
|
2010-06-10 23:30:29 +02:00
|
|
|
bool OnGameOver();
|
|
|
|
/** \brief Resets values from a previous game */
|
|
|
|
void OnNewGame ();
|
2010-11-22 20:00:44 +01:00
|
|
|
void OnShipExplode ();
|
2010-04-05 23:38:59 +02:00
|
|
|
|
2010-11-27 20:56:38 +01:00
|
|
|
/* Level loading etc. */
|
|
|
|
int DoLoadLevel (const char* filename);
|
|
|
|
int DoSaveLevel (const char* filename);
|
2011-03-23 08:13:27 +01:00
|
|
|
void LoadLevelFromIndex (unsigned int level_index);
|
2011-01-02 18:25:20 +01:00
|
|
|
void ResetLevel ();
|
2010-09-11 02:28:50 +02:00
|
|
|
|
2010-11-28 00:20:58 +01:00
|
|
|
void ReloadLevel();
|
2010-11-27 20:56:38 +01:00
|
|
|
void ProceedToNextLevel ();
|
2010-04-05 23:38:59 +02:00
|
|
|
int GetPlayerLives () { return mPlayerLives; };
|
2011-03-24 08:26:06 +01:00
|
|
|
void SetPlayerLives (int lives) { mPlayerLives = lives; };
|
2010-05-02 22:39:49 +02:00
|
|
|
unsigned int GetPoints () { return mPoints; };
|
2010-06-10 23:30:29 +02:00
|
|
|
std::string GetPlayerName() { return mPlayerName; };
|
2010-09-11 02:28:50 +02:00
|
|
|
void SetPlayerName(const std::string &name) {
|
|
|
|
Engine::LogDebug("new player name: %s", name.c_str());
|
|
|
|
mPlayerName = name;
|
|
|
|
};
|
2010-04-05 23:38:59 +02:00
|
|
|
|
2011-01-02 18:25:20 +01:00
|
|
|
std::string GetLevelName() { return mLevelName; };
|
|
|
|
void SetLevelName(const std::string &name) {
|
2011-02-12 16:34:47 +01:00
|
|
|
Engine::LogDebug("new level name: %s", name.c_str());
|
2011-01-02 18:25:20 +01:00
|
|
|
mLevelName = name;
|
|
|
|
}
|
|
|
|
|
2011-02-12 15:43:06 +01:00
|
|
|
std::string GetLevelAuthor() { return mLevelAuthor; };
|
|
|
|
void SetLevelAuthor(const std::string &author) {
|
2011-02-12 16:34:47 +01:00
|
|
|
Engine::LogDebug("new level author: %s", author.c_str());
|
2011-02-12 15:43:06 +01:00
|
|
|
mLevelAuthor = author;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetLevelTitle() { return mLevelTitle; };
|
|
|
|
void SetLevelTitle(const std::string &title) {
|
2011-02-12 16:34:47 +01:00
|
|
|
Engine::LogDebug("new level title: %s", title.c_str());
|
2011-02-12 15:43:06 +01:00
|
|
|
mLevelTitle = title;
|
|
|
|
}
|
|
|
|
|
2010-11-27 20:56:38 +01:00
|
|
|
/* Highscore */
|
2010-06-10 23:30:29 +02:00
|
|
|
struct HighscoreEntry {
|
|
|
|
HighscoreEntry(): name ("unknown"), points (0) { };
|
|
|
|
HighscoreEntry (const char *e_name, const unsigned int e_points):
|
|
|
|
name (e_name), points (e_points) { };
|
|
|
|
|
|
|
|
std::string name;
|
|
|
|
unsigned int points;
|
|
|
|
};
|
|
|
|
|
2011-03-16 17:03:41 +01:00
|
|
|
void ParseHighscoreStream (std::istream &highscore_stream);
|
2010-06-10 23:30:29 +02:00
|
|
|
void LoadHighscoreList ();
|
2011-03-16 17:03:41 +01:00
|
|
|
bool PullGlobalHighscore (std::stringstream &highscore_stream);
|
|
|
|
bool SubmitGlobalHigscoreEntry (const std::string &name, const unsigned int points);
|
|
|
|
void SubmitHighscoreEntry (const std::string &name, const unsigned int points);
|
|
|
|
unsigned int AddLocalHighscoreEntry(const std::string &name, const unsigned int points);
|
|
|
|
void LoadLocalHighscoreList ();
|
|
|
|
void SaveLocalHighscoreList ();
|
2011-03-27 22:16:19 +02:00
|
|
|
bool GetHighscoreIsOnline() { return mHighscoreIsOnline; };
|
2011-03-16 17:03:41 +01:00
|
|
|
|
2010-06-10 23:30:29 +02:00
|
|
|
std::list<HighscoreEntry> mHighscoreList;
|
|
|
|
unsigned int mNewestHighscoreEntryIndex;
|
|
|
|
|
2011-03-22 23:01:44 +01:00
|
|
|
unsigned int GetCurrentLevelIndex () {
|
|
|
|
return mCurrentLevelIndex;
|
|
|
|
}
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
protected:
|
|
|
|
/** \brief Initializes the system */
|
|
|
|
virtual int OnInit (int argc, char* argv[]);
|
2011-03-16 17:03:41 +01:00
|
|
|
virtual void OnDestroy();
|
2010-04-05 23:38:59 +02:00
|
|
|
virtual void OnRegisterCommands ();
|
|
|
|
|
|
|
|
virtual void OnCreateEntity (const int type, const unsigned int id);
|
|
|
|
virtual void OnKillEntity (const Engine::EntityBase *entity);
|
|
|
|
|
|
|
|
private:
|
2010-04-18 11:41:29 +02:00
|
|
|
unsigned int InitLevelList ();
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
/** \brief Keeps a list of all asteroids */
|
|
|
|
std::vector<unsigned int> mAsteroids;
|
|
|
|
|
|
|
|
int mPlayerLives;
|
2010-05-02 22:39:49 +02:00
|
|
|
unsigned int mPoints;
|
2010-04-18 11:41:29 +02:00
|
|
|
unsigned int mCurrentLevelIndex;
|
2011-01-02 18:25:20 +01:00
|
|
|
|
2010-06-10 23:30:29 +02:00
|
|
|
std::string mPlayerName;
|
|
|
|
std::vector<std::string> mLevelList;
|
2011-01-02 18:25:20 +01:00
|
|
|
std::string mLevelName;
|
2011-02-12 15:43:06 +01:00
|
|
|
std::string mLevelAuthor;
|
|
|
|
std::string mLevelTitle;
|
2010-04-18 11:41:29 +02:00
|
|
|
|
2011-03-16 17:03:41 +01:00
|
|
|
static Engine::Variable HighscoreServerName;
|
|
|
|
static Engine::Variable HighscoreServerPath;
|
|
|
|
static Engine::Variable UseServerHighscore;
|
|
|
|
static Engine::Variable UseServerHighscoreAsked;
|
|
|
|
|
2011-03-27 22:16:19 +02:00
|
|
|
bool mHighscoreIsOnline;
|
|
|
|
|
2010-07-28 18:02:12 +02:00
|
|
|
virtual bool OnReceiveEvent (const Engine::EventBasePtr &event);
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
friend class View;
|
2011-01-02 18:25:20 +01:00
|
|
|
friend class Controller;
|
2010-04-05 23:38:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _MODEL_H
|