Move Duplicate::setGameAndPlayersRack() to Game

This commit is contained in:
Olivier Teulière 2012-12-25 18:25:22 +01:00
parent c775682881
commit c138947138
4 changed files with 36 additions and 31 deletions

View file

@ -43,7 +43,6 @@
#include "cmd/player_rack_cmd.h"
#include "cmd/player_event_cmd.h"
#include "cmd/game_move_cmd.h"
#include "cmd/game_rack_cmd.h"
#include "cmd/master_move_cmd.h"
#include "ai_player.h"
#include "navigation.h"
@ -383,32 +382,6 @@ bool Duplicate::isArbitrationGame() const
}
void Duplicate::setGameAndPlayersRack(const PlayedRack &iRack)
{
// Set the game rack
Command *pCmd = new GameRackCmd(*this, iRack);
accessNavigation().addAndExecute(pCmd);
LOG_INFO("Setting players rack to '" + lfw(iRack.toString()) + "'");
// All the players have the same rack
BOOST_FOREACH(Player *player, m_players)
{
Command *pCmd = new PlayerRackCmd(*player, iRack);
accessNavigation().addAndExecute(pCmd);
}
// Assign a "no move" pseudo-move to all the players.
// This avoids the need to distinguish between "has not played yet"
// and "has played with no move".
// This is also practical to know at which turn the warnings, penalties
// and solos should be assigned.
BOOST_FOREACH(Player *player, m_players)
{
Command *pCmd = new PlayerMoveCmd(*player, Move());
accessNavigation().addAndExecute(pCmd);
}
}
void Duplicate::setSoloAuto(unsigned int minNbPlayers, int iSoloValue)
{
// Remove all existing solos

View file

@ -26,7 +26,6 @@
#include "logging.h"
class Player;
class PlayedRack;
class Move;
class PlayerEventCmd;
@ -113,9 +112,6 @@ protected:
/// Record a player move
void recordPlayerMove(Player &ioPlayer, const Move &iMove);
/// Helper function to set the game rack and the players rack at the same time
void setGameAndPlayersRack(const PlayedRack &iRack);
/**
* This function does not terminate the turn itself, but performs some
* checks to know whether or not it should be terminated (with a call to

View file

@ -43,6 +43,9 @@
#include "encoding.h"
#include "game_exception.h"
#include "turn.h"
#include "cmd/player_rack_cmd.h"
#include "cmd/player_move_cmd.h"
#include "cmd/game_rack_cmd.h"
#include "debug.h"
@ -611,6 +614,33 @@ int Game::checkPlayedWord(const wstring &iCoord,
}
void Game::setGameAndPlayersRack(const PlayedRack &iRack)
{
// Set the game rack
Command *pCmd = new GameRackCmd(*this, iRack);
accessNavigation().addAndExecute(pCmd);
LOG_INFO("Setting players rack to '" + lfw(iRack.toString()) + "'");
// All the players have the same rack
BOOST_FOREACH(Player *player, m_players)
{
Command *pCmd = new PlayerRackCmd(*player, iRack);
accessNavigation().addAndExecute(pCmd);
}
// Assign a "no move" pseudo-move to all the players.
// This avoids the need to distinguish between "has not played yet"
// and "has played with no move".
// This is also practical to know at which turn the warnings, penalties
// and solos should be assigned.
BOOST_FOREACH(Player *player, m_players)
{
Command *pCmd = new PlayerMoveCmd(*player, Move());
accessNavigation().addAndExecute(pCmd);
}
}
Game::CurrentPlayerCmd::CurrentPlayerCmd(Game &ioGame,
unsigned int iPlayerId)
: m_game(ioGame), m_newPlayerId(iPlayerId), m_oldPlayerId(0)

View file

@ -278,6 +278,12 @@ protected:
*/
PlayedRack helperSetRackManual(bool iCheck, const wstring &iLetters) const;
/**
* Helper function to set the game rack and the players rack at the same time.
* Shouldn't be used in free game mode.
*/
void setGameAndPlayersRack(const PlayedRack &iRack);
void nextPlayer();
/**