1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:27:44 +00:00

Snake: Persist high score

This commit is contained in:
Tibor Nagy 2020-02-25 19:36:46 +01:00 committed by Andreas Kling
parent 0d2bfe5c65
commit 6a892ea3a2
2 changed files with 8 additions and 4 deletions

View file

@ -25,6 +25,7 @@
*/
#include "SnakeGame.h"
#include <LibCore/ConfigFile.h>
#include <LibGUI/FontDatabase.h>
#include <LibGUI/Painter.h>
#include <LibGfx/Bitmap.h>
@ -42,8 +43,9 @@ SnakeGame::SnakeGame()
srand(time(nullptr));
reset();
m_high_score = 0;
m_high_score_text = "Best: 0";
auto config = Core::ConfigFile::get_for_app("Snake");
m_high_score = config->read_num_entry("Snake", "HighScore", 0);
m_high_score_text = String::format("Best: %u", m_high_score);
}
SnakeGame::~SnakeGame()
@ -149,6 +151,8 @@ void SnakeGame::timer_event(Core::TimerEvent&)
m_high_score = m_score;
m_high_score_text = String::format("Best: %u", m_high_score);
update(high_score_rect());
auto config = Core::ConfigFile::get_for_app("Snake");
config->write_num_entry("Snake", "HighScore", m_high_score);
}
update(score_rect());
dirty_cells.append(m_fruit);

View file

@ -37,14 +37,14 @@
int main(int argc, char** argv)
{
if (pledge("stdio rpath shared_buffer accept cpath unix fattr", nullptr) < 0) {
if (pledge("stdio rpath wpath cpath shared_buffer accept cpath unix fattr", nullptr) < 0) {
perror("pledge");
return 1;
}
GUI::Application app(argc, argv);
if (pledge("stdio rpath shared_buffer accept", nullptr) < 0) {
if (pledge("stdio rpath wpath cpath shared_buffer accept", nullptr) < 0) {
perror("pledge");
return 1;
}