From 6a892ea3a2586a07d02bc01cc88e0f3338b6cc50 Mon Sep 17 00:00:00 2001 From: Tibor Nagy Date: Tue, 25 Feb 2020 19:36:46 +0100 Subject: [PATCH] Snake: Persist high score --- Games/Snake/SnakeGame.cpp | 8 ++++++-- Games/Snake/main.cpp | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Games/Snake/SnakeGame.cpp b/Games/Snake/SnakeGame.cpp index 5c05446185..371ab5d91d 100644 --- a/Games/Snake/SnakeGame.cpp +++ b/Games/Snake/SnakeGame.cpp @@ -25,6 +25,7 @@ */ #include "SnakeGame.h" +#include #include #include #include @@ -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); diff --git a/Games/Snake/main.cpp b/Games/Snake/main.cpp index ca13e20ff4..39967a06f7 100644 --- a/Games/Snake/main.cpp +++ b/Games/Snake/main.cpp @@ -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; }