/** 
  * @return GameDetailDto
  *
  * @throws NotFoundHttpException if game was not found
  */
 private function getGameById($gameId)
 {
     $gameDetail = $this->gameService->getGameById($gameId);
     if ($gameDetail === null) {
         throw new NotFoundHttpException('Game cannot be found');
     }
     return $gameDetail;
 }
示例#2
0
 public function viewAction(Request $request, $gameId, $playerNumber)
 {
     $game = $this->gameService->getGameById($gameId);
     $player = $game !== null ? $game->getPlayerByNumber($playerNumber) : null;
     if ($game === null || $player === null) {
         throw new NotFoundHttpException('Game and/or player cannot be found');
     }
     $moves = $this->getMoves($player);
     $turnNumber = $game->getCurrentTurn()->getNumber() ?: null;
     $formObject = new PlayerForm($game->getId(), $player->getNumber(), $turnNumber, $moves);
     $form = $this->createForm(PlayerFormType::class, $formObject);
     return $this->handlePlayerForm($request, $form, $game, $player) ?: $this->getViewResponse($form, $game, $player);
 }
示例#3
0
 public function testAfterDealPlayerWithDoubleSixHasTurn()
 {
     $game = $this->createGame(42, 'test game');
     $this->expectForFindById(42, $game);
     $this->expectPersistForGame($game);
     $gameDetailDto = $this->gameService->getGameById(42);
     $this->assertNull($gameDetailDto->getCurrentTurn());
     $this->gameService->deal(42);
     $gameDetailDto = $this->gameService->getGameById(42);
     // check if player with current turn has double six
     $turnDto = $gameDetailDto->getCurrentTurn();
     $this->assertNotNull($turnDto);
     $currentPlayerNumber = $turnDto->getCurrentPlayerNumber();
     $this->assertPlayerHasStone($gameDetailDto, $currentPlayerNumber, new Dto\Stone(6, 6));
 }