solitare/gamestate.h

64 lines
1.9 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);
2024-12-03 00:55:54 +00:00
// Getters
2024-12-01 21:40:42 +00:00
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
2024-12-03 00:55:54 +00:00
// General functions
2024-12-01 21:40:42 +00:00
void dealCards();
void drawNextCard();
2024-12-03 00:55:54 +00:00
// Manual moves (from X to Y)
2024-12-01 21:40:42 +00:00
bool moveCardToColumn(int columnId);
bool moveThrownCardToFoundation(PlayingCard::Suit foundationId);
bool moveColumnCardToFoundation(int columnId, PlayingCard::Suit foundationId);
2024-12-03 00:55:54 +00:00
// Automatic moves (from X to auto)
bool autoMoveThrownCard();
bool autoMoveColumnCard(int columnId);
2024-12-01 21:40:42 +00:00
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-03 00:55:54 +00:00
bool tryAutoMoveCard(PlayingCard* cardToMove);
bool isMoveToColumnLegal(PlayingCard* cardToMove, int columnId);
2024-12-02 15:10:51 +00:00
void ensureColumnRevealed(int columnId);
2024-12-01 21:40:42 +00:00
};
#endif // GAMESTATE_H