1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 23:27:42 +00:00

Snake: Add pause/continue game menu action

This patch adds an action in the Snake's game menu that allows for easy
pausing/unpausing of the game state.

In order to do this, the commit adds new pause()/start() functions in
the SnakeGame class ;)
This commit is contained in:
Baitinq 2022-12-18 20:51:28 +01:00 committed by Tim Flynn
parent 3de5dcf383
commit b354e858c8
3 changed files with 30 additions and 2 deletions

View file

@ -53,6 +53,21 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
game->reset();
})));
static DeprecatedString const pause_text = "&Pause Game"sv;
auto const pause_icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/pause.png"sv));
static DeprecatedString const continue_text = "&Continue Game"sv;
auto const continue_icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/play.png"sv));
TRY(game_menu->try_add_action(GUI::Action::create(pause_text, { Mod_None, Key_Space }, pause_icon, [&](auto& action) {
if (game->has_timer()) {
game->pause();
action.set_text(continue_text);
action.set_icon(continue_icon);
} else {
game->start();
action.set_text(pause_text);
action.set_icon(pause_icon);
}
})));
TRY(game_menu->try_add_separator());
TRY(game_menu->try_add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the()->quit();