summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorJesse Buhagiar <jooster669@gmail.com>2021-05-18 21:43:02 +1000
committerAndreas Kling <kling@serenityos.org>2021-05-18 20:05:10 +0200
commit2f49241296eb4487729e4f8fafdb70d42abfc661 (patch)
tree19c59074e5eacbf6c3d7017cab85c25a0ba2c78c /Userland
parenta743075b9fb9e59a892d40a2e17b780ea297a1a9 (diff)
downloadserenity-2f49241296eb4487729e4f8fafdb70d42abfc661.zip
Solitaire: Prevent player dragging entire stack to foundation
Currently, it is possible for the player to drag an entire stack of cards to the foundation stack, provided the top card of the stack (i.e the "root" card) can be dropped onto the foundation stack. This causes an invalid state where, e.g, red cards end up in a black foundation stack, or vice versa.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Games/Solitaire/CardStack.cpp5
-rw-r--r--Userland/Games/Solitaire/CardStack.h2
-rw-r--r--Userland/Games/Solitaire/Game.cpp2
3 files changed, 6 insertions, 3 deletions
diff --git a/Userland/Games/Solitaire/CardStack.cpp b/Userland/Games/Solitaire/CardStack.cpp
index d7694b90bc..375264f226 100644
--- a/Userland/Games/Solitaire/CardStack.cpp
+++ b/Userland/Games/Solitaire/CardStack.cpp
@@ -131,7 +131,7 @@ void CardStack::add_all_grabbed_cards(const Gfx::IntPoint& click_location, Nonnu
}
}
-bool CardStack::is_allowed_to_push(const Card& card) const
+bool CardStack::is_allowed_to_push(const Card& card, size_t stack_size) const
{
if (m_type == Stock || m_type == Waste || m_type == Play)
return false;
@@ -148,6 +148,9 @@ bool CardStack::is_allowed_to_push(const Card& card) const
return false;
if (m_type == Foundation) {
+ // Prevent player from dragging an entire stack of cards to the foundation stack
+ if (stack_size > 1)
+ return false;
return top_card.type() == card.type() && m_stack.size() == card.value();
} else if (m_type == Normal) {
return top_card.color() != card.color() && top_card.value() == card.value() + 1;
diff --git a/Userland/Games/Solitaire/CardStack.h b/Userland/Games/Solitaire/CardStack.h
index 90ffec5282..2686bce8a4 100644
--- a/Userland/Games/Solitaire/CardStack.h
+++ b/Userland/Games/Solitaire/CardStack.h
@@ -42,7 +42,7 @@ public:
void move_to_stack(CardStack&);
void rebound_cards();
- bool is_allowed_to_push(const Card&) const;
+ bool is_allowed_to_push(const Card&, size_t stack_size = 1) const;
void add_all_grabbed_cards(const Gfx::IntPoint& click_location, NonnullRefPtrVector<Card>& grabbed);
void draw(GUI::Painter&, const Gfx::Color& background_color);
void clear();
diff --git a/Userland/Games/Solitaire/Game.cpp b/Userland/Games/Solitaire/Game.cpp
index 8578b7d446..7aab23456e 100644
--- a/Userland/Games/Solitaire/Game.cpp
+++ b/Userland/Games/Solitaire/Game.cpp
@@ -249,7 +249,7 @@ void Game::mouseup_event(GUI::MouseEvent& event)
for (auto& focused_card : m_focused_cards) {
if (stack.bounding_box().intersects(focused_card.rect())) {
- if (stack.is_allowed_to_push(m_focused_cards.at(0))) {
+ if (stack.is_allowed_to_push(m_focused_cards.at(0), m_focused_cards.size())) {
for (auto& to_intersect : m_focused_cards) {
mark_intersecting_stacks_dirty(to_intersect);
stack.push(to_intersect);