コード例 #1
0
 /**
  * @Route("/show/{game}", name="game_show")
  * @param Game $game
  * @param Request $request
  * @return Response
  */
 public function showGame(Game $game, Request $request)
 {
     //Проверяем и закрываем закончившиеся игры
     $this->get('app.service.game_helper')->closeFinishedTeamGames();
     $teamGame = $this->getDoctrine()->getRepository(TeamGame::class)->findActiveTeamGame($this->getUser()->getTeam());
     if ($teamGame && $game->getId() !== $teamGame->getGame()->getId()) {
         $teamGame = null;
     }
     $gameTask = $teamGame ? $this->getDoctrine()->getRepository(GameTask::class)->findCurrentTask($teamGame) : null;
     $codeForm = $this->createForm(ActiveGameCodeType::class);
     $codeForm->handleRequest($request);
     if ($teamGame && $gameTask && $codeForm->isValid()) {
         $taskCode = $this->getDoctrine()->getRepository(TaskCode::class)->findOneBy(['gameTask' => $gameTask, 'code' => $codeForm->getData()['code']]);
         if ($taskCode) {
             list($this->flashType, $this->flashMessage) = $this->get('app.service.game_helper')->processGame($teamGame, $gameTask, $taskCode, $this->getUser());
             $this->addFlashMessage();
             return $this->redirectToRoute('game_show', ['game' => $game->getId()]);
         } else {
             $this->flashMessage = 'Код не верен';
             $this->flashType = 'danger';
             $this->addFlashMessage();
         }
     }
     return $this->render('AppBundle:Game:show.html.twig', ['game' => $game, 'gameList' => $this->getDoctrine()->getRepository(Game::class)->findFutureGames(), 'teamGame' => $teamGame, 'gameTask' => $gameTask, 'form' => $codeForm->createView()]);
 }
コード例 #2
0
 /**
  * @Route("/secure/game/{id}", requirements={"id" = "\d+"}, name="game_view")
  */
 public function viewAction(Game $game, Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $headsForm = $this->createForm(new HeadsFlipType(), array('flipType' => Game::FLIP_TYPE_HEADS));
     $tailsForm = $this->createForm(new TailsFlipType(), array('flipType' => Game::FLIP_TYPE_TAILS));
     $removeForm = $this->createForm(new RemovePlayerType(), array(), array('action' => $this->generateUrl('game_remove_player', array('id' => $game->getId()))));
     $user = $this->getUser();
     if ($request->isMethod('POST')) {
         $flipType = $this->getFlipTypeFromForm($headsForm, $tailsForm, $request);
         $this->createPlayerAddToGameAndPersist($user, $game, $flipType, $em);
         if ($game->isGameReady()) {
             $this->playGame($game, $em);
             $replacementGame = $this->createReplacementGame($game, $em);
             $this->notifyPlayersOfGameUpdate($replacementGame);
             $this->notifyPlayersOfGameUpdate($game);
             return $this->redirectToRoute('game_play', array('id' => $game->getId()), 301);
         }
         $em->flush();
         $this->notifyPlayersOfGameUpdate($game);
     }
     $userInGame = $game->isUserInGame($user);
     $gameFinished = $game->getGameState() == Game::STATE_FINISHED;
     $liveGames = $em->getRepository('AppBundle:Game')->getUserLiveGames($this->getUser());
     return $this->render('game/view.html.twig', array('game' => $game, 'liveGames' => $liveGames, 'userInGame' => $game->isUserInGame($user), 'formHeads' => $headsForm->createView(), 'formTails' => $tailsForm->createView(), 'formRemove' => $removeForm->createView(), 'gameFinished' => $gameFinished));
 }
コード例 #3
0
 /**
  * Get replacement game
  *
  * @param Game $game
  * @return Game
  */
 public function getReplacementGame(Game $game, GameNameFinder $gameNameFinder)
 {
     $replacement = new Game(new RandomHeadTailsGenerator());
     $replacement->setName($gameNameFinder->getUniqueName());
     $replacement->setReplacedGameId($game->getId());
     return $replacement;
 }
コード例 #4
0
ファイル: GameController.php プロジェクト: OlliAB/doms-record
 /**
  * Creates a form to delete a Game entity.
  *
  * @param Game $game The Game entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Game $game)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('game_delete', array('id' => $game->getId())))->setMethod('DELETE')->getForm();
 }
コード例 #5
0
 /**
  * @param Client $client
  * @param Game $game
  * @param string $apiKey
  * @return Response
  */
 private function callGetEvents(Client $client, Game $game, $apiKey)
 {
     $client->request('GET', sprintf('/v1/games/%d/events', $game->getId()), [], [], ['HTTP_ACCEPT' => 'application/json', 'HTTP_AUTHORIZATION' => 'Bearer ' . $apiKey]);
     return $client->getResponse();
 }
コード例 #6
0
 /**
  * @Route("/{game}/{teamGame}/team/delete", name="admin_game_team_delete")
  * @param Game $game
  * @param TeamGame $teamGame
  * @return RedirectResponse
  */
 public function gameTeamDeleteAction(Game $game, TeamGame $teamGame)
 {
     $this->getDoctrine()->getManager()->remove($teamGame);
     $this->getDoctrine()->getManager()->flush();
     return $this->redirectToRoute('admin_game_team_list', ['game' => $game->getId()]);
 }