1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:47: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

@ -90,7 +90,7 @@ void Game::timer_event(Core::TimerEvent&)
void Game::create_new_animation_card()
{
auto card = Card::construct(static_cast<Card::Suit>(get_random_uniform(to_underlying(Card::Suit::__Count))), get_random_uniform(Card::card_count));
auto card = Card::construct(static_cast<Cards::Suit>(get_random_uniform(to_underlying(Cards::Suit::__Count))), static_cast<Cards::Rank>(get_random_uniform(to_underlying(Cards::Rank::__Count))));
card->set_position({ get_random_uniform(Game::width - Card::width), get_random_uniform(Game::height / 8) });
int x_sgn = card->position().x() > (Game::width / 2) ? -1 : 1;
@ -163,10 +163,10 @@ void Game::setup(Mode mode)
on_undo_availability_change(false);
for (int i = 0; i < Card::card_count; ++i) {
m_new_deck.append(Card::construct(Card::Suit::Clubs, i));
m_new_deck.append(Card::construct(Card::Suit::Spades, i));
m_new_deck.append(Card::construct(Card::Suit::Hearts, i));
m_new_deck.append(Card::construct(Card::Suit::Diamonds, i));
m_new_deck.append(Card::construct(Cards::Suit::Clubs, static_cast<Cards::Rank>(i)));
m_new_deck.append(Card::construct(Cards::Suit::Spades, static_cast<Cards::Rank>(i)));
m_new_deck.append(Card::construct(Cards::Suit::Hearts, static_cast<Cards::Rank>(i)));
m_new_deck.append(Card::construct(Cards::Suit::Diamonds, static_cast<Cards::Rank>(i)));
}
for (uint8_t i = 0; i < 200; ++i)