nsnake
Classic snake game for the terminal
Loading...
Searching...
No Matches
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
13class ScoreFileException : public std::exception
14{
15public:
16 ScoreFileException(std::string message):
17 message(message)
18 { }
19 ~ScoreFileException() throw()
20 { }
21
22 std::string message;
23};
24
28{
30 unsigned int points;
31
33 unsigned int speed;
34
37 std::string level;
38
40 int fruits;
41
44
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
88{
89public:
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
150private:
153 std::string level_name;
154
156 std::vector<ScoreEntry> entries;
157};
158
159#endif //SCORE_H_DEFINED
160
Custom exception class to specify an error that occurred during a level loading.
Definition ScoreFile.hpp:14
Stores points the player made on the game.
Definition ScoreFile.hpp:88
static std::string directory
Default directory where we store the game score files.
Definition ScoreFile.hpp:97
bool handle(ScoreEntry *score)
Checks if #score is the highest score and make it so.
ScoreFile(std::string levelName)
Creates a new score handler for the level #levelName.
Definition ScoreFile.cpp:91
static void eraseAll()
Erases all high score files.
Definition ScoreFile.cpp:71
void load()
Loads all high score entries based on a level name.
Definition ScoreFile.cpp:96
ScoreEntry * highScore
Maximum high score obtained for the current game.
static std::string extension
Default extension to save the score files.
void save()
Saves all the current scores on the file.
A single entry on the high-score file.
Definition ScoreFile.hpp:28
bool random_walls
If random walls were spawned on this level.
Definition ScoreFile.hpp:43
bool isLike(ScoreEntry &other)
Tells if both scores were made on exact same game settings.
Definition ScoreFile.cpp:30
std::string level
On which level the user made this score.
Definition ScoreFile.hpp:37
int fruits
How many fruits at once were allowed on this level.
Definition ScoreFile.hpp:40
bool teleport
If teleport was enabled on this level.
Definition ScoreFile.hpp:46
unsigned int speed
Under which game speed the score was made.
Definition ScoreFile.hpp:33
unsigned int points
How many points the user got.
Definition ScoreFile.hpp:30
ScoreEntry()
Creates an empty score entry.
Definition ScoreFile.cpp:15
Globals::Game::BoardSize board_size
How large was the game board on this score.
Definition ScoreFile.hpp:52