nsnake
Classic snake game for the terminal
ScoreFile.hpp
1 #ifndef SCORE_H_DEFINED
2 #define SCORE_H_DEFINED
3 
4 #include <Config/Globals.hpp>
5 
6 #include <string>
7 #include <vector>
8 #include <exception>
9 
13 class ScoreFileException : public std::exception
14 {
15 public:
16  ScoreFileException(std::string message):
17  message(message)
18  { }
19  ~ScoreFileException() throw()
20  { }
21 
22  std::string message;
23 };
24 
27 struct ScoreEntry
28 {
30  unsigned int points;
31 
33  unsigned int speed;
34 
37  std::string level;
38 
40  int fruits;
41 
44 
46  bool teleport;
47 
52  Globals::Game::BoardSize board_size;
53 
54  int board_scroll_delay;
55  bool board_scroll_left;
56  bool board_scroll_right;
57  bool board_scroll_up;
58  bool board_scroll_down;
59 
63  ScoreEntry();
64 
72  bool isLike(ScoreEntry& other);
73 };
74 
87 class ScoreFile
88 {
89 public:
97  static std::string directory;
98 
105  static std::string extension;
106 
112  static void eraseAll();
113 
117  ScoreFile(std::string levelName);
118 
127  void load();
128 
130  void save();
131 
138  bool handle(ScoreEntry* score);
139 
149 
150 private:
153  std::string level_name;
154 
156  std::vector<ScoreEntry> entries;
157 };
158 
159 #endif //SCORE_H_DEFINED
160 
ScoreEntry * highScore
Maximum high score obtained for the current game.
Definition: ScoreFile.hpp:148
Stores points the player made on the game.
Definition: ScoreFile.hpp:87
static std::string extension
Default extension to save the score files.
Definition: ScoreFile.hpp:105
int fruits
How many fruits at once were allowed on this level.
Definition: ScoreFile.hpp:40
std::string level
On which level the user made this score.
Definition: ScoreFile.hpp:37
Custom exception class to specify an error that occurred during a level loading.
Definition: ScoreFile.hpp:13
bool random_walls
If random walls were spawned on this level.
Definition: ScoreFile.hpp:43
Globals::Game::BoardSize board_size
How large was the game board on this score.
Definition: ScoreFile.hpp:52
bool teleport
If teleport was enabled on this level.
Definition: ScoreFile.hpp:46
static std::string directory
Default directory where we store the game score files.
Definition: ScoreFile.hpp:97
A single entry on the high-score file.
Definition: ScoreFile.hpp:27
unsigned int points
How many points the user got.
Definition: ScoreFile.hpp:30
unsigned int speed
Under which game speed the score was made.
Definition: ScoreFile.hpp:33