summaryrefslogtreecommitdiff
path: root/Userland/Games
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-05-24 14:00:09 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-25 21:05:35 +0200
commit4ba9cc82c00b62e3a440a798596d90b4af44b633 (patch)
tree7bf9a5bcc982d297718f087c8eaec63ee308d88d /Userland/Games
parent9a6c6a98e5d71f6bd2402fc614512c5814035fef (diff)
downloadserenity-4ba9cc82c00b62e3a440a798596d90b4af44b633.zip
Hearts: Move code to reposition cards into a separate method
Diffstat (limited to 'Userland/Games')
-rw-r--r--Userland/Games/Hearts/Game.cpp15
-rw-r--r--Userland/Games/Hearts/Game.h2
2 files changed, 12 insertions, 5 deletions
diff --git a/Userland/Games/Hearts/Game.cpp b/Userland/Games/Hearts/Game.cpp
index 6d9c2dc781..d51a418c92 100644
--- a/Userland/Games/Hearts/Game.cpp
+++ b/Userland/Games/Hearts/Game.cpp
@@ -122,11 +122,7 @@ void Game::setup(String player_name)
player.hand.append(card);
}
player.sort_hand();
- auto card_position = player.first_card_position;
- for (auto& card : player.hand) {
- card->set_position(card_position);
- card_position.translate_by(player.card_offset);
- }
+ reposition_hand(player);
}
advance_game();
@@ -519,6 +515,15 @@ bool Game::is_winner(Player& player)
return (max_score.value() != sum_points_of_all_cards && player_score == min_score.value()) || player_score == sum_points_of_all_cards;
}
+void Game::reposition_hand(Player& player)
+{
+ auto card_position = player.first_card_position;
+ for (auto& card : player.hand) {
+ card->set_position(card_position);
+ card_position.translate_by(player.card_offset);
+ }
+}
+
void Game::paint_event(GUI::PaintEvent& event)
{
GUI::Frame::paint_event(event);
diff --git a/Userland/Games/Hearts/Game.h b/Userland/Games/Hearts/Game.h
index 414479b37b..4be336b4b0 100644
--- a/Userland/Games/Hearts/Game.h
+++ b/Userland/Games/Hearts/Game.h
@@ -49,6 +49,8 @@ private:
bool other_player_has_lower_value_card(Player& player, Card& card);
bool other_player_has_higher_value_card(Player& player, Card& card);
+ void reposition_hand(Player& player);
+
void start_animation(NonnullRefPtrVector<Card> cards, Gfx::IntPoint const& end, Function<void()> did_finish_callback, int initial_delay_ms, int steps = 30);
void stop_animation();