diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-01-28 17:15:47 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-02-01 14:19:15 +0000 |
commit | 5de8b3878356e3bc2a3b81e356078a58c587bff7 (patch) | |
tree | 3fd9b133010c4d132f23514dcfaad769ccb06057 /Userland/Games | |
parent | e8d83b1ae12c08acc9be76b7aaddbd1d3f311412 (diff) | |
download | serenity-5de8b3878356e3bc2a3b81e356078a58c587bff7.zip |
Solitaire: Make double-click skip the new-game animation
Diffstat (limited to 'Userland/Games')
-rw-r--r-- | Userland/Games/Solitaire/Game.cpp | 58 | ||||
-rw-r--r-- | Userland/Games/Solitaire/Game.h | 1 |
2 files changed, 35 insertions, 24 deletions
diff --git a/Userland/Games/Solitaire/Game.cpp b/Userland/Games/Solitaire/Game.cpp index e7b48840d7..3b74ae3020 100644 --- a/Userland/Games/Solitaire/Game.cpp +++ b/Userland/Games/Solitaire/Game.cpp @@ -48,6 +48,35 @@ static float rand_float() return get_random_uniform(RAND_MAX) / static_cast<float>(RAND_MAX); } +void Game::deal_next_card() +{ + VERIFY(m_state == State::NewGameAnimation); + + auto& current_pile = stack_at_location(piles.at(m_new_game_animation_pile)); + + if (current_pile.count() < m_new_game_animation_pile) { + auto card = m_new_deck.take_last(); + card->set_upside_down(true); + current_pile.push(card).release_value_but_fixme_should_propagate_errors(); + } else { + current_pile.push(m_new_deck.take_last()).release_value_but_fixme_should_propagate_errors(); + ++m_new_game_animation_pile; + } + + update(current_pile.bounding_box()); + + if (m_new_game_animation_pile == piles.size()) { + auto& stock_pile = stack_at_location(Stock); + while (!m_new_deck.is_empty()) + stock_pile.push(m_new_deck.take_last()).release_value_but_fixme_should_propagate_errors(); + + update(stock_pile.bounding_box()); + + m_state = State::WaitingForNewGame; + stop_timer(); + } +} + void Game::timer_event(Core::TimerEvent&) { switch (m_state) { @@ -69,29 +98,7 @@ void Game::timer_event(Core::TimerEvent&) ++m_new_game_animation_delay; } else { m_new_game_animation_delay = 0; - auto& current_pile = stack_at_location(piles.at(m_new_game_animation_pile)); - - if (current_pile.count() < m_new_game_animation_pile) { - auto card = m_new_deck.take_last(); - card->set_upside_down(true); - current_pile.push(card).release_value_but_fixme_should_propagate_errors(); - } else { - current_pile.push(m_new_deck.take_last()).release_value_but_fixme_should_propagate_errors(); - ++m_new_game_animation_pile; - } - - update(current_pile.bounding_box()); - - if (m_new_game_animation_pile == piles.size()) { - auto& stock_pile = stack_at_location(Stock); - while (!m_new_deck.is_empty()) - stock_pile.push(m_new_deck.take_last()).release_value_but_fixme_should_propagate_errors(); - - update(stock_pile.bounding_box()); - - m_state = State::WaitingForNewGame; - stop_timer(); - } + deal_next_card(); } break; } @@ -365,8 +372,11 @@ void Game::doubleclick_event(GUI::MouseEvent& event) return; } - if (m_state == State::NewGameAnimation) + if (m_state == State::NewGameAnimation) { + while (m_state == State::NewGameAnimation) + deal_next_card(); return; + } auto click_location = event.position(); for (auto& to_check : stacks()) { diff --git a/Userland/Games/Solitaire/Game.h b/Userland/Games/Solitaire/Game.h index 97e71f2ceb..8e73da4969 100644 --- a/Userland/Games/Solitaire/Game.h +++ b/Userland/Games/Solitaire/Game.h @@ -187,6 +187,7 @@ private: void set_background_fill_enabled(bool); void check_for_game_over(); void clear_hovered_stack(); + void deal_next_card(); virtual void paint_event(GUI::PaintEvent&) override; virtual void mousedown_event(GUI::MouseEvent&) override; |