mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Solitaire: Track and persist high score
This commit is contained in:
parent
7d062d0033
commit
3d3a75f1b9
Notes:
sideshowbarker
2024-07-18 17:50:05 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/3d3a75f1b99 Pull-request: https://github.com/SerenityOS/serenity/pull/7257
1 changed files with 11 additions and 0 deletions
|
@ -50,6 +50,7 @@ int main(int argc, char** argv)
|
|||
window->set_title("Solitaire");
|
||||
|
||||
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) {
|
||||
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);
|
||||
};
|
||||
|
||||
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)
|
||||
update_mode(Solitaire::Mode::SingleCardDraw);
|
||||
|
||||
|
@ -84,6 +92,9 @@ int main(int argc, char** argv)
|
|||
|
||||
game.on_score_update = [&](uint32_t score) {
|
||||
statusbar.set_text(0, String::formatted("Score: {}", score));
|
||||
|
||||
if (score > high_score)
|
||||
update_high_score(score);
|
||||
};
|
||||
|
||||
uint64_t seconds_elapsed = 0;
|
||||
|
|
Loading…
Reference in a new issue