1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:37:35 +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

@ -59,6 +59,17 @@ SnakeGame::SnakeGame(NonnullRefPtrVector<Gfx::Bitmap> food_bitmaps)
m_high_score_text = DeprecatedString::formatted("Best: {}", m_high_score);
}
void SnakeGame::pause()
{
stop_timer();
}
void SnakeGame::start()
{
static constexpr int timer_ms = 100;
start_timer(timer_ms);
}
void SnakeGame::reset()
{
m_head = { m_rows / 2, m_columns / 2 };
@ -68,8 +79,8 @@ void SnakeGame::reset()
m_score_text = "Score: 0";
m_is_new_high_score = false;
m_velocity_queue.clear();
stop_timer();
start_timer(100);
pause();
start();
spawn_fruit();
update();
}