1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:57:35 +00:00

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.
This commit is contained in:
Sam Atkins 2022-08-20 20:21:33 +01:00 committed by Andreas Kling
parent 163a74e3e2
commit aac2488d5c
9 changed files with 121 additions and 75 deletions

View file

@ -55,13 +55,13 @@ void Game::setup(Mode mode)
switch (m_mode) {
case Mode::SingleSuit:
for (int j = 0; j < 8; j++) {
deck.append(Card::construct(Card::Suit::Spades, i));
deck.append(Card::construct(Cards::Suit::Spades, static_cast<Cards::Rank>(i)));
}
break;
case Mode::TwoSuit:
for (int j = 0; j < 4; j++) {
deck.append(Card::construct(Card::Suit::Spades, i));
deck.append(Card::construct(Card::Suit::Hearts, i));
deck.append(Card::construct(Cards::Suit::Spades, static_cast<Cards::Rank>(i)));
deck.append(Card::construct(Cards::Suit::Hearts, static_cast<Cards::Rank>(i)));
}
break;
default:
@ -150,15 +150,14 @@ void Game::detect_full_stacks()
break;
if (!started) {
if (card.value() != 0) {
if (card.rank() != Cards::Rank::Ace)
break;
}
started = true;
color = card.color();
} else if (card.value() != last_value + 1 || card.color() != color) {
} else if (to_underlying(card.rank()) != last_value + 1 || card.color() != color) {
break;
} else if (card.value() == Card::card_count - 1) {
} else if (card.rank() == Cards::Rank::King) {
// we have a full set
auto original_current_rect = current_pile.bounding_box();
@ -174,7 +173,7 @@ void Game::detect_full_stacks()
update_score(101);
}
last_value = card.value();
last_value = to_underlying(card.rank());
}
}