mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:27:34 +00:00
Solitaire: Track and persist high score
This commit is contained in:
parent
7d062d0033
commit
3d3a75f1b9
1 changed files with 11 additions and 0 deletions
|
@ -50,6 +50,7 @@ int main(int argc, char** argv)
|
||||||
window->set_title("Solitaire");
|
window->set_title("Solitaire");
|
||||||
|
|
||||||
auto mode = static_cast<Solitaire::Mode>(config->read_num_entry("Settings", "Mode", static_cast<int>(Solitaire::Mode::SingleCardDraw)));
|
auto mode = static_cast<Solitaire::Mode>(config->read_num_entry("Settings", "Mode", static_cast<int>(Solitaire::Mode::SingleCardDraw)));
|
||||||
|
auto high_score = static_cast<u32>(config->read_num_entry("Game", "HighScore", 0));
|
||||||
|
|
||||||
auto update_mode = [&](Solitaire::Mode new_mode) {
|
auto update_mode = [&](Solitaire::Mode new_mode) {
|
||||||
mode = new_mode;
|
mode = new_mode;
|
||||||
|
@ -58,6 +59,13 @@ int main(int argc, char** argv)
|
||||||
GUI::MessageBox::show(window, "Configuration could not be saved", "Error", GUI::MessageBox::Type::Error);
|
GUI::MessageBox::show(window, "Configuration could not be saved", "Error", GUI::MessageBox::Type::Error);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto update_high_score = [&](u32 new_high_score) {
|
||||||
|
high_score = new_high_score;
|
||||||
|
config->write_num_entry("Game", "HighScore", static_cast<int>(high_score));
|
||||||
|
if (!config->sync())
|
||||||
|
GUI::MessageBox::show(window, "Configuration could not be saved", "Error", GUI::MessageBox::Type::Error);
|
||||||
|
};
|
||||||
|
|
||||||
if (mode >= Solitaire::Mode::__Count)
|
if (mode >= Solitaire::Mode::__Count)
|
||||||
update_mode(Solitaire::Mode::SingleCardDraw);
|
update_mode(Solitaire::Mode::SingleCardDraw);
|
||||||
|
|
||||||
|
@ -84,6 +92,9 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
game.on_score_update = [&](uint32_t score) {
|
game.on_score_update = [&](uint32_t score) {
|
||||||
statusbar.set_text(0, String::formatted("Score: {}", score));
|
statusbar.set_text(0, String::formatted("Score: {}", score));
|
||||||
|
|
||||||
|
if (score > high_score)
|
||||||
|
update_high_score(score);
|
||||||
};
|
};
|
||||||
|
|
||||||
uint64_t seconds_elapsed = 0;
|
uint64_t seconds_elapsed = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue