Beispiel #1
0
 /**
  * @param int    $turnNumber
  * @param Stone  $stone
  * @param string $side       Side, on of Table::SIDE_LEFT or Table::SIDE_RIGHT
  */
 public function __construct($turnNumber, Stone $stone, $side)
 {
     parent::__construct($turnNumber);
     if (!in_array($side, [Table::SIDE_LEFT, Table::SIDE_RIGHT])) {
         throw new InvalidArgumentException('Invalid side');
     }
     $this->stone = $stone;
     $this->side = $side;
 }
Beispiel #2
0
 /**
  * @param Player $player
  * @param Move   $move
  */
 public function addMove(Player $player, Move $move)
 {
     if (!$this->getState()->isStarted()) {
         throw new InvalidMoveException('Game has not started or is already finished');
     }
     if ($move->getTurnNumber() !== $this->getCurrentTurn()->getNumber()) {
         throw new InvalidMoveException('Turn number move does not match current game turn number');
     }
     if ($player->getNumber() !== $this->getCurrentTurn()->getPlayerNumber()) {
         throw new InvalidMoveException('player cannot move at the current turn (current player is ' . $this->getCurrentTurn()->getPlayerNumber() . ')');
     }
     $this->nextTurn();
 }