nsnake
Classic snake game for the terminal
Toggle main menu visibility
Loading...
Searching...
No Matches
src
Game
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
43
bool
random_walls
;
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
148
ScoreEntry
*
highScore
;
149
150
private
:
153
std::string level_name;
154
156
std::vector<ScoreEntry> entries;
157
};
158
159
#endif
//SCORE_H_DEFINED
160
ScoreFile::directory
static std::string directory
Default directory where we store the game score files.
Definition
ScoreFile.hpp:97
ScoreFile::handle
bool handle(ScoreEntry *score)
Checks if score is the highest score and make it so.
Definition
ScoreFile.cpp:263
ScoreFile::ScoreFile
ScoreFile(std::string levelName)
Creates a new score handler for the level levelName.
Definition
ScoreFile.cpp:91
ScoreFile::eraseAll
static void eraseAll()
Erases all high score files.
Definition
ScoreFile.cpp:71
ScoreFile::load
void load()
Loads all high score entries based on a level name.
Definition
ScoreFile.cpp:96
ScoreFile::highScore
ScoreEntry * highScore
Maximum high score obtained for the current game.
Definition
ScoreFile.hpp:148
ScoreFile::extension
static std::string extension
Default extension to save the score files.
Definition
ScoreFile.hpp:105
ScoreFile::save
void save()
Saves all the current scores on the file.
Definition
ScoreFile.cpp:202
ScoreEntry
A single entry on the high-score file.
Definition
ScoreFile.hpp:28
ScoreEntry::random_walls
bool random_walls
If random walls were spawned on this level.
Definition
ScoreFile.hpp:43
ScoreEntry::isLike
bool isLike(ScoreEntry &other)
Tells if both scores were made on exact same game settings.
Definition
ScoreFile.cpp:30
ScoreEntry::level
std::string level
On which level the user made this score.
Definition
ScoreFile.hpp:37
ScoreEntry::fruits
int fruits
How many fruits at once were allowed on this level.
Definition
ScoreFile.hpp:40
ScoreEntry::teleport
bool teleport
If teleport was enabled on this level.
Definition
ScoreFile.hpp:46
ScoreEntry::speed
unsigned int speed
Under which game speed the score was made.
Definition
ScoreFile.hpp:33
ScoreEntry::points
unsigned int points
How many points the user got.
Definition
ScoreFile.hpp:30
ScoreEntry::ScoreEntry
ScoreEntry()
Creates an empty score entry.
Definition
ScoreFile.cpp:15
ScoreEntry::board_size
Globals::Game::BoardSize board_size
How large was the game board on this score.
Definition
ScoreFile.hpp:52
Generated on
for nsnake by
1.17.0