solitare/src/playingcard.h

70 lines
1.5 KiB
C
Raw Normal View History

2024-12-01 18:43:49 +00:00
#ifndef PLAYINGCARD_H
#define PLAYINGCARD_H
#include <QObject>
#include <qqmlintegration.h>
2024-12-01 18:43:49 +00:00
2024-12-05 02:06:34 +00:00
class PlayingCard : public QObject {
2024-12-01 18:43:49 +00:00
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("Use C++ logic to instantiate")
Q_ENUMS(Value)
Q_ENUMS(Suit)
2024-12-02 23:33:22 +00:00
Q_PROPERTY(Suit suit READ suit WRITE setSuit NOTIFY suitChanged REQUIRED)
Q_PROPERTY(Value value READ value WRITE setValue NOTIFY valueChanged REQUIRED)
2024-12-01 18:43:49 +00:00
2024-12-02 23:33:22 +00:00
Q_PROPERTY(QString valueString READ valueString NOTIFY valueChanged)
Q_PROPERTY(QString suitString READ suitString NOTIFY suitChanged)
2024-12-05 02:06:34 +00:00
public:
enum Value {
Ace = 1,
Two = 2,
Three = 3,
Four = 4,
Five = 5,
Six = 6,
Seven = 7,
Eight = 8,
Nine = 9,
Ten = 10,
Jack = 11,
Queen = 12,
King = 13,
};
2024-12-01 18:43:49 +00:00
enum Suit {
Clubs,
Diamonds,
Hearts,
Spades,
};
2024-12-01 18:43:49 +00:00
explicit PlayingCard(QObject* parent = nullptr, const Suit& suit = Suit::Clubs, const Value& value = Value::Ace);
Suit suit() const;
QString suitString() const;
2024-12-05 02:06:34 +00:00
void setSuit(const Suit& suit);
Value value() const;
QString valueString() const;
2024-12-05 02:06:34 +00:00
void setValue(const Value& value);
2024-12-01 18:43:49 +00:00
2024-12-03 14:14:27 +00:00
QString toString() const;
2024-12-07 12:30:02 +00:00
static QList<PlayingCard*> createDeck(QObject* parent = nullptr);
2024-12-05 02:06:34 +00:00
static bool areOppositeColors(const PlayingCard& card1, const PlayingCard& card2);
2024-12-05 02:06:34 +00:00
signals:
2024-12-02 23:33:22 +00:00
void suitChanged();
void valueChanged();
2024-12-01 18:43:49 +00:00
2024-12-05 02:06:34 +00:00
private:
Suit m_suit;
Value m_value;
2024-12-01 18:43:49 +00:00
};
#endif // PLAYINGCARD_H