summaryrefslogtreecommitdiff
path: root/Userland/Games
diff options
context:
space:
mode:
authorJamie Mansfield <jmansfield@cadixdev.org>2021-07-15 17:00:07 +0100
committerAndreas Kling <kling@serenityos.org>2021-07-15 19:52:14 +0200
commitc0bc884295491cea629483521979fe578755c4b9 (patch)
treeaaa86554030c5cf32fbda9d7cab07cb03f9c925c /Userland/Games
parent1021aba22603fa536478001f7c2a363e356582c8 (diff)
downloadserenity-c0bc884295491cea629483521979fe578755c4b9.zip
Spider: Automatically reveal top cards
This matches basically all other Spider implementations I've played, and makes playing much easier :) I have left click-to-reveal in place, but mostly incase there is a condition I've forgotten about.
Diffstat (limited to 'Userland/Games')
-rw-r--r--Userland/Games/Spider/Game.cpp16
-rw-r--r--Userland/Games/Spider/Game.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Games/Spider/Game.cpp b/Userland/Games/Spider/Game.cpp
index 4b003528ef..aa2393b5fa 100644
--- a/Userland/Games/Spider/Game.cpp
+++ b/Userland/Games/Spider/Game.cpp
@@ -114,6 +114,18 @@ void Game::draw_cards()
update();
}
+void Game::ensure_top_card_is_visible(NonnullRefPtr<CardStack> stack)
+{
+ if (stack->is_empty())
+ return;
+
+ auto& top_card = stack->peek();
+ if (top_card.is_upside_down()) {
+ top_card.set_upside_down(false);
+ update(top_card.rect());
+ }
+}
+
void Game::detect_full_stacks()
{
auto& completed_stack = stack(Completed);
@@ -143,6 +155,8 @@ void Game::detect_full_stacks()
completed_stack.push(current_pile.pop());
}
+ ensure_top_card_is_visible(current_pile);
+
update_score(101);
}
@@ -301,6 +315,8 @@ void Game::mouseup_event(GUI::MouseEvent& event)
detect_full_stacks();
+ ensure_top_card_is_visible(*m_focused_stack);
+
rebound = false;
break;
}
diff --git a/Userland/Games/Spider/Game.h b/Userland/Games/Spider/Game.h
index 94f48b43c9..cea44a1961 100644
--- a/Userland/Games/Spider/Game.h
+++ b/Userland/Games/Spider/Game.h
@@ -67,6 +67,7 @@ private:
void start_timer_if_necessary();
void update_score(int delta);
void draw_cards();
+ void ensure_top_card_is_visible(NonnullRefPtr<CardStack> stack);
void detect_full_stacks();
void detect_victory();