diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-08-20 20:21:33 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-22 12:50:41 +0200 |
commit | aac2488d5c8ac3119c17db06776c41c3649372b6 (patch) | |
tree | 9eda5142be80f8e27063e1421028d63fa0968965 /Userland/Libraries/LibCards/CardStack.cpp | |
parent | 163a74e3e2f73bca7f68e34fc087a735a120eaff (diff) | |
download | serenity-aac2488d5c8ac3119c17db06776c41c3649372b6.zip |
LibCards+Games: Replace card "value" int with a Rank enum
Because `card->value() == 11` is a lot less clear than `card->rank() ==
Cards::Rank::Queen`, and also safer.
Put this, along with the `Suit` enum, in the `Cards` namespace directly
instead of inside `Cards::Card`. Slightly less typing that way.
Diffstat (limited to 'Userland/Libraries/LibCards/CardStack.cpp')
-rw-r--r-- | Userland/Libraries/LibCards/CardStack.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Userland/Libraries/LibCards/CardStack.cpp b/Userland/Libraries/LibCards/CardStack.cpp index 7826a3938c..591df4f054 100644 --- a/Userland/Libraries/LibCards/CardStack.cpp +++ b/Userland/Libraries/LibCards/CardStack.cpp @@ -170,12 +170,12 @@ void CardStack::add_all_grabbed_cards(Gfx::IntPoint const& click_location, Nonnu break; } - if (!color_match || card.value() != last_value - 1) { + if (!color_match || to_underlying(card.rank()) != last_value - 1) { valid_stack = false; break; } } - last_value = card.value(); + last_value = to_underlying(card.rank()); last_color = card.color(); } @@ -195,13 +195,13 @@ bool CardStack::is_allowed_to_push(Card const& card, size_t stack_size, Movement if (m_type == Type::Normal && is_empty()) { // FIXME: proper solution for this if (movement_rule == MovementRule::Alternating) { - return card.value() == 12; + return card.rank() == Rank::King; } return true; } if (m_type == Type::Foundation && is_empty()) - return card.value() == 0; + return card.rank() == Rank::Ace; if (!is_empty()) { auto& top_card = peek(); @@ -212,7 +212,7 @@ bool CardStack::is_allowed_to_push(Card const& card, size_t stack_size, Movement // Prevent player from dragging an entire stack of cards to the foundation stack if (stack_size > 1) return false; - return top_card.suit() == card.suit() && m_stack.size() == card.value(); + return top_card.suit() == card.suit() && m_stack.size() == to_underlying(card.rank()); } else if (m_type == Type::Normal) { bool color_match; switch (movement_rule) { @@ -227,7 +227,7 @@ bool CardStack::is_allowed_to_push(Card const& card, size_t stack_size, Movement break; } - return color_match && top_card.value() == card.value() + 1; + return color_match && to_underlying(top_card.rank()) == to_underlying(card.rank()) + 1; } VERIFY_NOT_REACHED(); |