mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 18:37:36 +00:00
Pong: Restart timer if necessary
When the player runs into a game over condition, Game's timer is stopped. In order for reset() to work properly, the timer has to be started again. The condition is tracked via a new member variable, `m_game_over`. To prevent confusion, game_over() has been renamed to show_game_over_message().
This commit is contained in:
parent
0abdeb474f
commit
02d2a300e7
2 changed files with 11 additions and 3 deletions
|
@ -36,6 +36,11 @@ void Game::reset_paddles()
|
|||
|
||||
void Game::reset()
|
||||
{
|
||||
if (m_game_over) {
|
||||
m_game_over = false;
|
||||
start_timer(16);
|
||||
}
|
||||
|
||||
// Make sure the current ball disappears.
|
||||
update(enclosing_int_rect(m_ball.rect()));
|
||||
|
||||
|
@ -162,7 +167,7 @@ void Game::reset_ball(int serve_to_player)
|
|||
m_ball.velocity = { velocity_x, velocity_y };
|
||||
}
|
||||
|
||||
void Game::game_over(int winner)
|
||||
void Game::show_game_over_message(int winner)
|
||||
{
|
||||
GUI::MessageBox::show(window(), String::formatted("Player {} wins!", winner), "Pong", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::OK);
|
||||
}
|
||||
|
@ -183,7 +188,8 @@ void Game::round_over(int winner)
|
|||
}
|
||||
|
||||
if (m_player_1_score == m_score_to_win || m_player_2_score == m_score_to_win) {
|
||||
game_over(winner);
|
||||
m_game_over = true;
|
||||
show_game_over_message(winner);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue