diff --git a/game/duplicate.cpp b/game/duplicate.cpp index 7228c67..4754512 100644 --- a/game/duplicate.cpp +++ b/game/duplicate.cpp @@ -151,6 +151,12 @@ void Duplicate::start() } +bool Duplicate::isFinished() const +{ + return m_finished; +} + + void Duplicate::tryEndTurn() { for (unsigned int i = 0; i < getNPlayers(); i++) diff --git a/game/duplicate.h b/game/duplicate.h index fa3954d..b17f8ef 100644 --- a/game/duplicate.h +++ b/game/duplicate.h @@ -73,6 +73,8 @@ public: */ virtual void start(); + virtual bool isFinished() const; + /** * See description of Game::play() for the possible return values. * Note that if the "duplicate-reject-invalid" setting is set to false diff --git a/game/freegame.cpp b/game/freegame.cpp index 3a51bf5..5165d7d 100644 --- a/game/freegame.cpp +++ b/game/freegame.cpp @@ -148,6 +148,12 @@ void FreeGame::start() } +bool FreeGame::isFinished() const +{ + return m_finished; +} + + int FreeGame::endTurn() { const Move &move = getCurrentPlayer().getLastMove(); diff --git a/game/freegame.h b/game/freegame.h index 0f4e636..a51f85c 100644 --- a/game/freegame.h +++ b/game/freegame.h @@ -57,6 +57,8 @@ public: */ virtual void start(); + virtual bool isFinished() const; + /** * See description of Game::play() for the possible return values. * Note that if the "freegame-reject-invalid" setting is set to false diff --git a/game/game.h b/game/game.h index b0af6c3..5ea35f3 100644 --- a/game/game.h +++ b/game/game.h @@ -147,6 +147,13 @@ public: */ virtual void start() = 0; + /** + * Indicate whether we reached the end of the game. + * This should be checked regularly. + * XXX: using a signal would be nice here... + */ + virtual bool isFinished() const = 0; + /** * Method used by human players to play the word iWord at coordinates * iCoord, and end the turn (if possible) diff --git a/game/public_game.cpp b/game/public_game.cpp index cb9f80c..6815012 100644 --- a/game/public_game.cpp +++ b/game/public_game.cpp @@ -144,6 +144,12 @@ void PublicGame::start() } +bool PublicGame::isFinished() const +{ + return m_game.isFinished(); +} + + int PublicGame::play(const wstring &iWord, const wstring &iCoord) { return m_game.play(iCoord, iWord); diff --git a/game/public_game.h b/game/public_game.h index 9a7236c..f0d2f78 100644 --- a/game/public_game.h +++ b/game/public_game.h @@ -134,6 +134,13 @@ public: */ void start(); + /** + * Indicate whether we reached the end of the game. + * This should be checked regularly. + * XXX: using a signal would be nice here... + */ + bool isFinished() const; + /** * Method used by human players to play the word iWord at coordinates * iCoord, and end the turn (if possible) diff --git a/game/training.cpp b/game/training.cpp index 343b69a..0ae33a6 100644 --- a/game/training.cpp +++ b/game/training.cpp @@ -131,6 +131,14 @@ void Training::start() } +bool Training::isFinished() const +{ + // The game is finished when there is no more tile + // (in the bag or in the racks) + return getBag().getNbTiles() == 0; +} + + void Training::endTurn() { m_results.clear(); diff --git a/game/training.h b/game/training.h index 25ddd94..cb4fc17 100644 --- a/game/training.h +++ b/game/training.h @@ -56,6 +56,8 @@ public: *************************/ virtual void start(); + virtual bool isFinished() const; + /// See description of Game::play() virtual int play(const wstring &iCoord, const wstring &iWord); diff --git a/qt/main_window.cpp b/qt/main_window.cpp index 1bcf0bd..a2e83fd 100644 --- a/qt/main_window.cpp +++ b/qt/main_window.cpp @@ -223,6 +223,8 @@ void MainWindow::refresh() m_actionHistoryNextTurn->setEnabled(!isLastTurn); m_actionHistoryLastTurn->setEnabled(!isLastTurn); m_actionHistoryReplayTurn->setEnabled(!isLastTurn); + if (m_game->isFinished()) + displayInfoMsg(_q("End of the game")); #ifdef DEBUG //m_game->printTurns(); #endif