summaryrefslogtreecommitdiff
path: root/Userland/Games/Hearts
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Games/Hearts')
-rw-r--r--Userland/Games/Hearts/Game.cpp21
-rw-r--r--Userland/Games/Hearts/Game.h2
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 };