/** * @file game_state.h * @ingroup GameLogic */ //! \todo Document this file. #ifndef COCKATRICE_GAME_STATE_H #define COCKATRICE_GAME_STATE_H #include #include #include #include class AbstractGame; class AbstractClient; class QTimer; class GameState : public QObject { Q_OBJECT public: explicit GameState(AbstractGame *parent, int secondsElapsed, int hostId, bool isLocalGame, QList clients, bool gameStateKnown, bool resuming, int currentPhase, bool gameClosed); void setHostId(int _hostId) { if (hostId == _hostId) { return; } hostId = _hostId; emit hostChanged(hostId); } QList getClients() const { return clients; } bool getIsLocalGame() const { return isLocalGame; } bool isResuming() const { return resuming; } void setResuming(bool _resuming) { resuming = _resuming; } bool isGameStateKnown() const { return gameStateKnown; } int getCurrentPhase() const { return currentPhase; } void setCurrentPhase(int phase) { currentPhase = phase; emit activePhaseChanged(phase); } void setActivePlayer(int activePlayerId) { activePlayer = activePlayerId; emit activePlayerChanged(activePlayer); } int getActivePlayer() const { return activePlayer; } void setGameClosed(bool closed) { gameClosed = closed; } bool isGameClosed() const { return gameClosed; } void onStartedChanged(bool _started) { if (_started) { emit gameStarted(_started); } else { emit gameStopped(); } } void setGameStateKnown(bool known) { gameStateKnown = known; } int getHostId() const { return hostId; } void setSeatOrder(const QList &order) { if (seatOrder != order) { seatOrder = order; emit seatOrderChanged(seatOrder); } } QList getSeatOrder() const { return seatOrder; } int getSecondsElapsed() const { return secondsElapsed; } signals: void updateTimeElapsedLabel(QString newTime); void gameStarted(bool resuming); void gameStopped(); void activePhaseChanged(int activePhase); void activePlayerChanged(int playerId); void hostChanged(int hostId); void seatOrderChanged(const QList &seatOrder); public slots: void incrementGameTime(); void setGameTime(int _secondsElapsed); public: static QString formatElapsedTime(int _secondsElapsed); private: QTimer *gameTimer; int secondsElapsed; int hostId; const bool isLocalGame; QList clients; bool gameStateKnown; bool resuming; int currentPhase; int activePlayer; bool gameClosed; //! Player ids in seating (turn) order, first to play first. Empty until the //! server sends an order, in which case players are laid out in id order. QList seatOrder; }; #endif // COCKATRICE_GAME_STATE_H