solitare/gamestate.h
2024-12-03 00:33:22 +01:00

47 lines
1.4 KiB
C++

#ifndef GAMESTATE_H
#define GAMESTATE_H
#include <QObject>
#include "playingcard.h"
#include "columnslot.h"
class GameState : public QObject
{
Q_OBJECT
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)
public:
explicit GameState(QObject *parent = nullptr);
QList<PlayingCard*> drawPile() const;
QList<PlayingCard*> throwawayPile() const;
QList<QList<ColumnSlot*>> columns() const;
QList<QList<PlayingCard*>> foundation() const;
void dealCards();
void drawNextCard();
bool moveCardToColumn(int columnId);
bool moveThrownCardToFoundation(PlayingCard::Suit foundationId);
bool moveColumnCardToFoundation(int columnId, PlayingCard::Suit foundationId);
signals:
void drawPileChanged();
void throwawayPileChanged();
void columnsChanged();
void foundationChanged();
private:
QList<PlayingCard*> m_drawPile;
QList<PlayingCard*> m_throwawayPile;
QList<QList<ColumnSlot*>> m_columns;
QList<QList<PlayingCard*>> m_foundation;
bool tryMoveCardToFoundation(PlayingCard::Suit foundationId, PlayingCard* cardToMove);
void ensureColumnRevealed(int columnId);
};
#endif // GAMESTATE_H