示例#1
0
 /**
  * @param Domain\Game $game
  *
  * @return Dto\GameDetail
  */
 private function mapGameToGameDetailDto(Domain\Game $game)
 {
     $builder = (new Dto\GameDetailBuilder())->id($game->getId())->name($game->getName())->state($game->getState()->getName());
     foreach ($game->getPlayers() as $player) {
         $builder->addPlayer($player->getNumber(), $player->getStones());
     }
     if ($game->getCurrentTurn() !== null) {
         $builder->turn($game->getCurrentTurn()->getNumber(), $game->getCurrentTurn()->getPlayerNumber());
     }
     return $builder->get();
 }
示例#2
0
 /**
  * @param Play $play
  */
 public function play(Play $play)
 {
     if (!$this->hasStone($play->getStone())) {
         throw new InvalidMoveException('player does not have stone');
     }
     try {
         $this->removeStone($play->getStone());
         $this->game->addMove($this, $play);
     } catch (InvalidMoveException $e) {
         $this->addStones([$play->getStone()]);
         throw $e;
     }
 }
示例#3
0
 private function assertPlayerCount($playerCount, Game $game)
 {
     $this->assertCount($playerCount, $game->getPlayers());
 }
 /**
  * helper function to assign stones to players
  *
  * @param Game $game
  * @param array $playerStones array of stone values (first value is top value, second value
  *      is bottom values). The array keys are player numbers
  */
 private function setGameStones(Game $game, array $playerStones)
 {
     $players = $game->getPlayers();
     foreach ($playerStones as $playerNumber => $stoneValues) {
         $stones = array_map(function (array $values) {
             return new Stone($values[0], $values[1]);
         }, $stoneValues);
         $players[$playerNumber]->addStones($stones);
     }
 }