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:
parent
0d2bfe5c65
commit
6a892ea3a2
2 changed files with 8 additions and 4 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue