diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-24 14:44:48 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-25 21:05:35 +0200 |
commit | fab073f33cefdb4053ce00d1daacc8b91a13f9ff (patch) | |
tree | f5f5f4f845b44580df08dacd195cab9ad0c75c88 /Userland/Games/Hearts | |
parent | 89d38b7e94a3d05aaa4092b4dc5bf1e31984d471 (diff) | |
download | serenity-fab073f33cefdb4053ce00d1daacc8b91a13f9ff.zip |
Hearts: Move card click handler into a separate method
Diffstat (limited to 'Userland/Games/Hearts')
-rw-r--r-- | Userland/Games/Hearts/Game.cpp | 21 | ||||
-rw-r--r-- | Userland/Games/Hearts/Game.h | 2 |
2 files changed, 15 insertions, 8 deletions
diff --git a/Userland/Games/Hearts/Game.cpp b/Userland/Games/Hearts/Game.cpp index d51a418c92..7c29907db4 100644 --- a/Userland/Games/Hearts/Game.cpp +++ b/Userland/Games/Hearts/Game.cpp @@ -464,6 +464,18 @@ bool Game::are_hearts_broken() const return false; } +void Game::card_clicked(size_t card_index, Card& card) +{ + String explanation; + if (!is_valid_play(m_players[0], card, &explanation)) { + on_status_change(String::formatted("You can't play this card: {}", explanation)); + continue_game_after_delay(); + return; + } + play_card(m_players[0], card_index); + update(); +} + void Game::mouseup_event(GUI::MouseEvent& event) { GUI::Frame::mouseup_event(event); @@ -479,14 +491,7 @@ void Game::mouseup_event(GUI::MouseEvent& event) if (card.is_null()) continue; if (card->rect().contains(event.position())) { - String explanation; - if (!is_valid_play(m_players[0], *card, &explanation)) { - on_status_change(String::formatted("You can't play this card: {}", explanation)); - continue_game_after_delay(); - return; - } - play_card(m_players[0], i); - update(); + card_clicked(i, *card); break; } } diff --git a/Userland/Games/Hearts/Game.h b/Userland/Games/Hearts/Game.h index 4be336b4b0..54f3a37373 100644 --- a/Userland/Games/Hearts/Game.h +++ b/Userland/Games/Hearts/Game.h @@ -59,6 +59,8 @@ private: virtual void keydown_event(GUI::KeyEvent&) override; virtual void timer_event(Core::TimerEvent&) override; + void card_clicked(size_t card_index, Card& card); + Player m_players[4]; NonnullRefPtrVector<Card> m_trick; Player* m_leading_player { nullptr }; |