42 if (this->
level.empty())
47 this->speed == other.
speed &&
48 this->board_scroll_delay == other.board_scroll_delay &&
49 this->board_scroll_left == other.board_scroll_left &&
50 this->board_scroll_right == other.board_scroll_right &&
51 this->board_scroll_up == other.board_scroll_up &&
52 this->board_scroll_down == other.board_scroll_down &&
61 this->speed == other.
speed &&
62 this->board_scroll_delay == other.board_scroll_delay &&
63 this->board_scroll_left == other.board_scroll_left &&
64 this->board_scroll_right == other.board_scroll_right &&
65 this->board_scroll_up == other.board_scroll_up &&
66 this->board_scroll_down == other.board_scroll_down);
112 if (this->level_name.empty())
113 score_file = Globals::Config::scoresFile;
115 if (! Utils::File::exists(score_file))
120 file.open(score_file.c_str());
122 std::stringstream buffer;
123 buffer << file.rdbuf();
126 std::stringstream contents;
127 contents << Utils::Base64::decode(buffer.str());
130 INI::Parser ini(contents);
135 std::string version = ini[
"version"];
140 Globals::Error::old_version_score_file =
true;
147 for (INI::Level::Sections::const_iterator it = ini.top().ordered_sections.begin();
148 it != ini.top().ordered_sections.end();
153 INI::Level ini_score = (*it)->second;
156 entry.
level = ini_score[
"level"];
157 entry.
points = Utils::String::to<unsigned int>(ini_score[
"points"]);
158 entry.
speed = Utils::String::to<unsigned int>(ini_score[
"speed"]);
159 entry.
fruits = Utils::String::to<int>(ini_score[
"fruits"]);
160 entry.
random_walls = Utils::String::to<bool>(ini_score[
"random_walls"]);
161 entry.
teleport = Utils::String::to<bool>(ini_score[
"teleport"]);
163 entry.board_scroll_delay = Utils::String::to<int>(ini_score[
"board_scroll_delay"]);
164 entry.board_scroll_left = Utils::String::to<bool>(ini_score[
"board_scroll_left"]);
165 entry.board_scroll_right = Utils::String::to<bool>(ini_score[
"board_scroll_right"]);
166 entry.board_scroll_up = Utils::String::to<bool>(ini_score[
"board_scroll_up"]);
167 entry.board_scroll_down = Utils::String::to<bool>(ini_score[
"board_scroll_down"]);
169 int board_size = Utils::String::to<int>(ini_score[
"board_size"]);
170 entry.
board_size = Globals::Game::intToBoardSize(board_size);
172 this->entries.push_back(entry);
178 tmp_score.
level = this->level_name;
179 tmp_score.
speed = Globals::Game::starting_speed;
180 tmp_score.
fruits = Globals::Game::fruits_at_once;
182 tmp_score.
teleport = Globals::Game::teleport;
183 tmp_score.
board_size = Globals::Game::board_size;
184 tmp_score.board_scroll_delay = Globals::Game::board_scroll_delay;
185 tmp_score.board_scroll_left = Globals::Game::board_scroll_left;
186 tmp_score.board_scroll_right = Globals::Game::board_scroll_right;
187 tmp_score.board_scroll_up = Globals::Game::board_scroll_up;
188 tmp_score.board_scroll_down = Globals::Game::board_scroll_down;
190 for (
size_t i = 0; i < (this->entries.size()); i++)
192 if (tmp_score.
isLike(this->entries[i]))
200 this->entries.push_back(tmp_score);
201 this->
highScore = &(this->entries[this->entries.size() - 1]);
214 if (this->level_name.empty())
215 score_file = Globals::Config::scoresFile;
219 if (! Utils::File::exists(score_file))
221 Utils::File::create(score_file);
223 if (! Utils::File::exists(score_file))
230 ini.top().addKey(
"version", std::string(VERSION));
233 for (
size_t i = 0; i < (this->entries.size()); i++)
235 std::string score_name =
"score" + Utils::String::toString(i);
237 ini.top().addGroup(score_name);
239 ini(score_name).addKey(
"level", this->entries[i].level);
240 ini(score_name).addKey(
"points", Utils::String::toString(this->entries[i].points));
241 ini(score_name).addKey(
"speed", Utils::String::toString(this->entries[i].speed));
242 ini(score_name).addKey(
"fruits", Utils::String::toString(this->entries[i].fruits));
244 ini(score_name).addKey(
"random_walls", Utils::String::toString(this->entries[i].random_walls));
245 ini(score_name).addKey(
"teleport", Utils::String::toString(this->entries[i].teleport));
247 int board_size = Globals::Game::boardSizeToInt(this->entries[i].board_size);
248 ini(score_name).addKey(
"board_size", Utils::String::toString(board_size));
250 ini(score_name).addKey(
"board_scroll_delay", Utils::String::toString(this->entries[i].board_scroll_delay));
251 ini(score_name).addKey(
"board_scroll_left", Utils::String::toString(this->entries[i].board_scroll_left));
252 ini(score_name).addKey(
"board_scroll_right", Utils::String::toString(this->entries[i].board_scroll_right));
253 ini(score_name).addKey(
"board_scroll_up", Utils::String::toString(this->entries[i].board_scroll_up));
254 ini(score_name).addKey(
"board_scroll_down", Utils::String::toString(this->entries[i].board_scroll_down));
257 std::stringstream contents;
261 file.open(score_file.c_str());
262 file << Utils::Base64::encode(contents.str());
A single entry on the high-score file.
bool random_walls
If random walls were spawned on this level.
bool isLike(ScoreEntry &other)
Tells if both scores were made on exact same game settings.
std::string level
On which level the user made this score.
int fruits
How many fruits at once were allowed on this level.
bool teleport
If teleport was enabled on this level.
unsigned int speed
Under which game speed the score was made.
unsigned int points
How many points the user got.
ScoreEntry()
Creates an empty score entry.
Globals::Game::BoardSize board_size
How large was the game board on this score.