From c0bc884295491cea629483521979fe578755c4b9 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Thu, 15 Jul 2021 17:00:07 +0100 Subject: [PATCH] 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. --- Userland/Games/Spider/Game.cpp | 16 ++++++++++++++++ Userland/Games/Spider/Game.h | 1 + 2 files changed, 17 insertions(+) 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 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 stack); void detect_full_stacks(); void detect_victory();