/** 
  * @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;
 }
Esempio n. 2
0
 /**
  * @param Request       $request
  * @param FormInterface $form
  * @param GameDetailDto $game
  * @param PlayerDto     $player
  *
  * @return Response|null
  */
 private function handlePlayerForm(Request $request, FormInterface $form, GameDetail $game, Player $player)
 {
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         if ($form->get('play')->isClicked()) {
             $turnNumber = $form->getData()->getTurnNumber();
             $move = $form->getData()->getMove();
             if ($move && $move->isPlay()) {
                 $play = new Play($turnNumber, new Stone($move->getStoneTopValue(), $move->getStoneBottomValue()), $move->getSide() === 'left' ? Play::SIDE_LEFT : Play::SIDE_RIGHT);
                 $this->gameService->play($game->getId(), $player->getNumber(), $play);
                 return $this->redirectToRoute(self::ROUTE_PLAYER_DETAIL, ['gameId' => $form->getData()->getGameId(), 'playerNumber' => $form->getData()->getPlayerNumber()]);
             }
         }
     }
     return;
 }
 /**
  * @return Response
  */
 private function getIndexResponse(FormInterface $form)
 {
     $games = $this->gameService->getRecentGames();
     return $this->render('game/game-index.html.twig', ['form' => $form->createView(), 'games' => $games]);
 }
Esempio n. 4
0
 /** @expectedException \Llvdl\Domino\Domain\Exception\DominoException */
 public function testDealGameWithNonExistingGameThrowsException()
 {
     $this->expectForFindById(42, NULL);
     $this->gameService->deal(42);
 }