solitare/gamestate.h

54 lines
1.6 KiB
C
Raw Normal View History

2024-12-01 21:40:42 +00:00
#ifndef GAMESTATE_H
#define GAMESTATE_H
#include <QObject>
#include "playingcard.h"
2024-12-02 15:10:51 +00:00
#include "columnslot.h"
2024-12-01 21:40:42 +00:00
class GameState : public QObject
{
Q_OBJECT
2024-12-02 23:33:22 +00:00
Q_PROPERTY(QList<PlayingCard*> drawPile READ drawPile NOTIFY drawPileChanged)
Q_PROPERTY(QList<PlayingCard*> throwawayPile READ throwawayPile NOTIFY throwawayPileChanged)
Q_PROPERTY(QList<QList<ColumnSlot*>> columns READ columns NOTIFY columnsChanged)
Q_PROPERTY(QList<QList<PlayingCard*>> foundation READ foundation NOTIFY foundationChanged)
2024-12-03 00:33:12 +00:00
Q_PROPERTY(bool gameWon READ gameWon NOTIFY gameWonChanged)
2024-12-01 21:40:42 +00:00
public:
explicit GameState(QObject *parent = nullptr);
QList<PlayingCard*> drawPile() const;
QList<PlayingCard*> throwawayPile() const;
2024-12-02 15:10:51 +00:00
QList<QList<ColumnSlot*>> columns() const;
2024-12-01 21:40:42 +00:00
QList<QList<PlayingCard*>> foundation() const;
2024-12-03 00:33:12 +00:00
bool gameWon() const;
2024-12-01 21:40:42 +00:00
void dealCards();
void drawNextCard();
bool moveCardToColumn(int columnId);
bool moveThrownCardToFoundation(PlayingCard::Suit foundationId);
bool moveColumnCardToFoundation(int columnId, PlayingCard::Suit foundationId);
signals:
2024-12-02 23:33:22 +00:00
void drawPileChanged();
void throwawayPileChanged();
void columnsChanged();
void foundationChanged();
2024-12-03 00:33:12 +00:00
void gameWonChanged();
private slots:
void onFoundationChanged();
2024-12-01 21:40:42 +00:00
private:
QList<PlayingCard*> m_drawPile;
QList<PlayingCard*> m_throwawayPile;
2024-12-02 15:10:51 +00:00
QList<QList<ColumnSlot*>> m_columns;
2024-12-01 21:40:42 +00:00
QList<QList<PlayingCard*>> m_foundation;
2024-12-03 00:33:12 +00:00
bool m_gameWon;
2024-12-01 21:40:42 +00:00
bool tryMoveCardToFoundation(PlayingCard::Suit foundationId, PlayingCard* cardToMove);
2024-12-02 15:10:51 +00:00
void ensureColumnRevealed(int columnId);
2024-12-01 21:40:42 +00:00
};
#endif // GAMESTATE_H