74 lines
2.3 KiB
C++
74 lines
2.3 KiB
C++
#ifndef GAMESTATE_H
|
|
#define GAMESTATE_H
|
|
|
|
#include <QObject>
|
|
#include <qqmlintegration.h>
|
|
#include "playingcard.h"
|
|
#include "columnslot.h"
|
|
|
|
class GameState : public QObject
|
|
{
|
|
Q_OBJECT
|
|
QML_ELEMENT
|
|
QML_SINGLETON
|
|
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)
|
|
Q_PROPERTY(bool gameWon READ gameWon NOTIFY gameWonChanged)
|
|
|
|
public:
|
|
explicit GameState(QObject *parent = nullptr);
|
|
|
|
// Getters
|
|
QList<PlayingCard*> drawPile() const;
|
|
QList<PlayingCard*> throwawayPile() const;
|
|
QList<QList<ColumnSlot*>> columns() const;
|
|
QList<QList<PlayingCard*>> foundation() const;
|
|
bool gameWon() const;
|
|
|
|
// General functions
|
|
Q_INVOKABLE void dealCards();
|
|
Q_INVOKABLE void setupWinningDeck();
|
|
Q_INVOKABLE void drawNextCard();
|
|
|
|
// Manual moves (from X to Y)
|
|
Q_INVOKABLE bool moveThrownCardToColumn(int columnId);
|
|
Q_INVOKABLE bool moveThrownCardToFoundation(int foundationId);
|
|
Q_INVOKABLE bool moveColumnCardToColumn(int fromColumnId, int toColumnId, int fromCardIndex);
|
|
Q_INVOKABLE bool moveColumnCardToFoundation(int columnId, int foundationId);
|
|
|
|
// Automatic moves (from X to auto)
|
|
Q_INVOKABLE bool autoMoveThrownCard();
|
|
Q_INVOKABLE bool autoMoveColumnCard(int columnId, int cardIndex);
|
|
|
|
signals:
|
|
void drawPileChanged();
|
|
void throwawayPileChanged();
|
|
void columnsChanged();
|
|
void foundationChanged();
|
|
void gameWonChanged();
|
|
|
|
private slots:
|
|
void onFoundationChanged();
|
|
|
|
private:
|
|
QList<PlayingCard*> m_drawPile;
|
|
QList<PlayingCard*> m_throwawayPile;
|
|
QList<QList<ColumnSlot*>> m_columns;
|
|
QList<QList<PlayingCard*>> m_foundation;
|
|
bool m_gameWon;
|
|
|
|
void cleanupBoard(bool emitChanges);
|
|
|
|
bool tryAutoMoveSingleCard(PlayingCard& cardToMove, int skipColumnId = -1);
|
|
bool tryAutoMoveMultipleCards(const QList<PlayingCard*>& cards, int skipColumnId);
|
|
|
|
bool isFoundationMoveValid(const PlayingCard& cardToMove, int foundationId);
|
|
bool isColumnMoveValid(const PlayingCard& cardToMove, int columnId);
|
|
|
|
void ensureColumnRevealed(int columnId);
|
|
};
|
|
|
|
#endif // GAMESTATE_H
|