mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:07:45 +00:00
LibCards+Games: Change name of card type to card suit
Playing cards have a `suit` such as `hearts`/`diamonds`, not a `type`. Make the internal naming consistent with the way playing cards are typically named.
This commit is contained in:
parent
4c5e9f5633
commit
a51fce6c0f
9 changed files with 78 additions and 78 deletions
|
@ -67,10 +67,10 @@ static constexpr Gfx::CharacterBitmap s_club {
|
|||
static RefPtr<Gfx::Bitmap> s_background;
|
||||
static RefPtr<Gfx::Bitmap> s_background_inverted;
|
||||
|
||||
Card::Card(Type type, uint8_t value)
|
||||
Card::Card(Suit suit, uint8_t value)
|
||||
: m_rect(Gfx::IntRect({}, { width, height }))
|
||||
, m_front(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { width, height }).release_value_but_fixme_should_propagate_errors())
|
||||
, m_type(type)
|
||||
, m_suit(suit)
|
||||
, m_value(value)
|
||||
{
|
||||
VERIFY(value < card_count);
|
||||
|
@ -111,15 +111,15 @@ Card::Card(Type type, uint8_t value)
|
|||
painter.draw_text(text_rect, label, font, Gfx::TextAlignment::Center, color());
|
||||
|
||||
auto const& symbol = [&]() -> Gfx::CharacterBitmap const& {
|
||||
switch (m_type) {
|
||||
case Type::Diamonds:
|
||||
switch (m_suit) {
|
||||
case Suit::Diamonds:
|
||||
return s_diamond;
|
||||
case Type::Clubs:
|
||||
case Suit::Clubs:
|
||||
return s_club;
|
||||
break;
|
||||
case Type::Spades:
|
||||
case Suit::Spades:
|
||||
return s_spade;
|
||||
case Type::Hearts:
|
||||
case Suit::Hearts:
|
||||
return s_heart;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"
|
||||
};
|
||||
|
||||
enum class Type {
|
||||
enum class Suit {
|
||||
Clubs,
|
||||
Diamonds,
|
||||
Spades,
|
||||
|
@ -43,13 +43,13 @@ public:
|
|||
Gfx::IntPoint position() const { return m_rect.location(); }
|
||||
const Gfx::IntPoint& old_position() const { return m_old_position; }
|
||||
uint8_t value() const { return m_value; };
|
||||
Type type() const { return m_type; }
|
||||
Suit suit() const { return m_suit; }
|
||||
|
||||
bool is_old_position_valid() const { return m_old_position_valid; }
|
||||
bool is_moving() const { return m_moving; }
|
||||
bool is_upside_down() const { return m_upside_down; }
|
||||
bool is_inverted() const { return m_inverted; }
|
||||
Gfx::Color color() const { return (m_type == Type::Diamonds || m_type == Type::Hearts) ? Color::Red : Color::Black; }
|
||||
Gfx::Color color() const { return (m_suit == Suit::Diamonds || m_suit == Suit::Hearts) ? Color::Red : Color::Black; }
|
||||
|
||||
void set_position(const Gfx::IntPoint p) { m_rect.set_location(p); }
|
||||
void set_moving(bool moving) { m_moving = moving; }
|
||||
|
@ -63,7 +63,7 @@ public:
|
|||
void clear_and_draw(GUI::Painter&, const Color& background_color);
|
||||
|
||||
private:
|
||||
Card(Type type, uint8_t value);
|
||||
Card(Suit suit, uint8_t value);
|
||||
|
||||
static NonnullRefPtr<Gfx::Bitmap> invert_bitmap(Gfx::Bitmap&);
|
||||
|
||||
|
@ -71,7 +71,7 @@ private:
|
|||
NonnullRefPtr<Gfx::Bitmap> m_front;
|
||||
RefPtr<Gfx::Bitmap> m_front_inverted;
|
||||
Gfx::IntPoint m_old_position;
|
||||
Type m_type;
|
||||
Suit m_suit;
|
||||
uint8_t m_value;
|
||||
bool m_old_position_valid { false };
|
||||
bool m_moving { false };
|
||||
|
@ -85,25 +85,25 @@ template<>
|
|||
struct AK::Formatter<Cards::Card> : Formatter<FormatString> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Cards::Card const& card)
|
||||
{
|
||||
StringView type;
|
||||
StringView suit;
|
||||
|
||||
switch (card.type()) {
|
||||
case Cards::Card::Type::Clubs:
|
||||
type = "C"sv;
|
||||
switch (card.suit()) {
|
||||
case Cards::Card::Suit::Clubs:
|
||||
suit = "C"sv;
|
||||
break;
|
||||
case Cards::Card::Type::Diamonds:
|
||||
type = "D"sv;
|
||||
case Cards::Card::Suit::Diamonds:
|
||||
suit = "D"sv;
|
||||
break;
|
||||
case Cards::Card::Type::Hearts:
|
||||
type = "H"sv;
|
||||
case Cards::Card::Suit::Hearts:
|
||||
suit = "H"sv;
|
||||
break;
|
||||
case Cards::Card::Type::Spades:
|
||||
type = "S"sv;
|
||||
case Cards::Card::Suit::Spades:
|
||||
suit = "S"sv;
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
return Formatter<FormatString>::format(builder, "{:>2}{}", Cards::Card::labels[card.value()], type);
|
||||
return Formatter<FormatString>::format(builder, "{:>2}{}", Cards::Card::labels[card.value()], suit);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -212,7 +212,7 @@ bool CardStack::is_allowed_to_push(const Card& 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.type() == card.type() && m_stack.size() == card.value();
|
||||
return top_card.suit() == card.suit() && m_stack.size() == card.value();
|
||||
} else if (m_type == Type::Normal) {
|
||||
bool color_match;
|
||||
switch (movement_rule) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue