2024-12-01 18:43:49 +00:00
|
|
|
#ifndef PLAYINGCARD_H
|
|
|
|
#define PLAYINGCARD_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2024-12-03 14:05:22 +00:00
|
|
|
#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
|
2024-12-03 14:05:22 +00:00
|
|
|
QML_ELEMENT
|
|
|
|
QML_UNCREATABLE("Use C++ logic to instantiate")
|
2024-12-01 20:17:09 +00:00
|
|
|
|
|
|
|
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-01 20:17:09 +00:00
|
|
|
|
2024-12-05 02:06:34 +00:00
|
|
|
public:
|
2024-12-01 20:17:09 +00:00
|
|
|
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
|
|
|
|
2024-12-01 20:17:09 +00:00
|
|
|
enum Suit {
|
|
|
|
Clubs,
|
|
|
|
Diamonds,
|
|
|
|
Hearts,
|
|
|
|
Spades,
|
|
|
|
};
|
2024-12-01 18:43:49 +00:00
|
|
|
|
2024-12-06 03:33:29 +00:00
|
|
|
explicit PlayingCard(QObject* parent = nullptr, const Suit& suit = Suit::Clubs, const Value& value = Value::Ace);
|
2024-12-01 20:17:09 +00:00
|
|
|
|
|
|
|
Suit suit() const;
|
|
|
|
QString suitString() const;
|
2024-12-05 02:06:34 +00:00
|
|
|
void setSuit(const Suit& suit);
|
2024-12-01 20:17:09 +00:00
|
|
|
|
|
|
|
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-01 20:17:09 +00:00
|
|
|
|
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:
|
2024-12-01 20:17:09 +00:00
|
|
|
Suit m_suit;
|
|
|
|
Value m_value;
|
2024-12-01 18:43:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PLAYINGCARD_H
|