Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function canGetData()
 {
     $players = [new Player(1, [new Stone(1, 1), new Stone(2, 0)]), new Player(2, [new Stone(3, 3)]), new Player(3, [new Stone(6, 0), new Stone(6, 1)]), new Player(4, [new Stone(4, 1), new Stone(4, 5)])];
     $gameDetail = new GameDetail(123, 'my name', GameDetail::STATE_STARTED, $players, [new Stone(5, 5), new Stone(6, 6), new Stone(6, 5)], new Turn(11, 3));
     $this->assertSame(123, $gameDetail->getId());
     $this->assertsame('my name', $gameDetail->getName());
     $this->assertSame(GameDetail::STATE_STARTED, $gameDetail->getState());
     $this->assertSame(1, $gameDetail->getPlayers()[0]->getNumber());
     $this->assertSame(2, $gameDetail->getPlayers()[1]->getNumber());
     $this->assertSame(3, $gameDetail->getPlayers()[2]->getNumber());
     $this->assertSame(4, $gameDetail->getPlayers()[3]->getNumber());
     $this->assertStones([new Stone(1, 1), new Stone(2, 0)], $gameDetail->getPlayers()[0]->getStones());
     $this->assertStones([new Stone(3, 3)], $gameDetail->getPlayers()[1]->getStones());
     $this->assertStones([new Stone(6, 0), new Stone(6, 1)], $gameDetail->getPlayers()[2]->getStones());
     $this->assertStones([new Stone(4, 1), new Stone(4, 5)], $gameDetail->getPlayers()[3]->getStones());
     $this->assertStones([new Stone(5, 5), new Stone(6, 6), new Stone(6, 5)], $gameDetail->getTableStones());
     $this->assertSame(11, $gameDetail->getCurrentTurn()->getNumber());
     $this->assertSame(3, $gameDetail->getCurrentTurn()->getCurrentPlayerNumber());
 }
Ejemplo n.º 3
0
 private function assertPlayerHasStone(Dto\GameDetail $game, $playerNumber, Dto\Stone $stoneDto)
 {
     $playerWithPlayerNumber = null;
     foreach ($game->getPlayers() as $player) {
         if ($player->getNumber() === $playerNumber) {
             $this->assertNull($playerWithPlayerNumber, 'only one player has given player number');
             $playerWithPlayerNumber = $player;
         }
     }
     $this->assertNotNull($playerWithPlayerNumber, 'player with player number found');
     $this->assertContainsStone($playerWithPlayerNumber->getStones(), $stoneDto);
 }