summaryrefslogtreecommitdiff
path: root/Userland/Games
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-05-26 09:22:19 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-26 19:57:08 +0200
commit971f4ca71cdb8a052637d68a9bf41f5f2f100907 (patch)
treef1d0ac762e7c164d5dc627d367743bd49b4cd67b /Userland/Games
parent2c772d184882dbdce0ec532f59c87743819f2e0d (diff)
downloadserenity-971f4ca71cdb8a052637d68a9bf41f5f2f100907.zip
Hearts: Highlight cards when an invalid play is attempted
This briefly inverts the selected card when the user attempts to make an invalid play.
Diffstat (limited to 'Userland/Games')
-rw-r--r--Userland/Games/Hearts/Game.cpp10
-rw-r--r--Userland/Games/Hearts/Game.h2
2 files changed, 12 insertions, 0 deletions
diff --git a/Userland/Games/Hearts/Game.cpp b/Userland/Games/Hearts/Game.cpp
index 3c921e9d0b..a968fde40f 100644
--- a/Userland/Games/Hearts/Game.cpp
+++ b/Userland/Games/Hearts/Game.cpp
@@ -402,6 +402,11 @@ void Game::advance_game()
if (m_animation_playing)
return;
+ if (m_inverted_card) {
+ m_inverted_card->set_inverted(false);
+ m_inverted_card.clear();
+ }
+
if (m_state == State::Play && game_ended()) {
m_state = State::GameEnded;
on_status_change("Game ended.");
@@ -638,6 +643,11 @@ void Game::card_clicked_during_play(size_t card_index, Card& card)
{
String explanation;
if (!is_valid_play(m_players[0], card, &explanation)) {
+ if (m_inverted_card)
+ m_inverted_card->set_inverted(false);
+ card.set_inverted(true);
+ m_inverted_card = card;
+ update();
on_status_change(String::formatted("You can't play this card: {}", explanation));
continue_game_after_delay();
return;
diff --git a/Userland/Games/Hearts/Game.h b/Userland/Games/Hearts/Game.h
index c21beb37a9..c54fbf21bc 100644
--- a/Userland/Games/Hearts/Game.h
+++ b/Userland/Games/Hearts/Game.h
@@ -106,6 +106,8 @@ private:
int m_animation_current_step { 0 };
int m_animation_steps { 0 };
OwnPtr<Function<void()>> m_animation_did_finish;
+
+ RefPtr<Card> m_inverted_card;
};
}