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
|
|
|
|
|
|
|
class PlayingCard : public QObject
|
|
|
|
{
|
|
|
|
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-01 18:43:49 +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-01 21:36:01 +00:00
|
|
|
explicit PlayingCard(const Suit &suit = Suit::Clubs, const Value &value = Value::Ace, QObject *parent = nullptr);
|
2024-12-01 20:17:09 +00:00
|
|
|
|
|
|
|
Suit suit() const;
|
|
|
|
QString suitString() const;
|
|
|
|
void setSuit(const Suit &suit);
|
|
|
|
|
|
|
|
Value value() const;
|
|
|
|
QString valueString() const;
|
|
|
|
void setValue(const Value &value);
|
2024-12-01 18:43:49 +00:00
|
|
|
|
2024-12-01 20:17:09 +00:00
|
|
|
static QList<PlayingCard*> createDeck();
|
2024-12-01 21:40:42 +00:00
|
|
|
static bool areOppositeColors(const PlayingCard &card1, const PlayingCard &card2);
|
2024-12-01 20:17:09 +00:00
|
|
|
|
2024-12-01 18:43:49 +00:00
|
|
|
signals:
|
2024-12-02 23:33:22 +00:00
|
|
|
void suitChanged();
|
|
|
|
void valueChanged();
|
2024-12-01 18:43:49 +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
|