Ejemplo n.º 1
0
 /**
  * @Route("/emulator")
  * @Template()
  */
 public function indexAction()
 {
     $entityManager = $this->getDoctrine()->getManager();
     $repo = $entityManager->getRepository("HackathonGameBundle:Game");
     $game = $repo->findCurrentGame();
     $formatter = new TeletextFormatter($game);
     return array('text' => $formatter->getFormat());
 }
Ejemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Get the current game
     $entityManager = $this->getContainer()->get('doctrine')->getManager();
     $repo = $entityManager->getRepository("HackathonGameBundle:Game");
     $currentGame = $repo->findCurrentGame();
     // Check if the round finished
     $timeTillRoundFinished = $currentGame->secondsUntilRoundEnd();
     if ($timeTillRoundFinished <= 0) {
         // The round finished. So let's find out on what the crowd decided
         $userRepo = $entityManager->getRepository("HackathonGameBundle:User");
         $result = $userRepo->findRoundResult($currentGame);
         echo "Round result:\n ";
         var_dump($result);
         if ($result !== NULL) {
             // Create a new GameTurn object
             $turn = new GameTurn();
             $turn->setMove($result["selection"]);
             $turn->setTeam($currentGame->getCurrentTeam());
             $currentGame->addTurn($turn);
             $entityManager->persist($turn);
             // Reset the user selection
             $currentGame->resetUserSelections();
             $gameLogic = new ConnectFour($currentGame);
             $winnerTeam = $gameLogic->checkWin();
             if ($winnerTeam !== NULL) {
                 // We have a winner
                 echo "The winner is: " . $winnerTeam . "\n";
                 $currentGame->setWinnerTeam($winnerTeam);
                 $currentGame->setIsFinished(true);
                 // And need to start a new game
                 echo "Starting new Game\n";
                 $newGame = new Game();
                 $entityManager->persist($newGame);
             } else {
                 // The round ended! Let's start a new one!
                 $currentGame->startNewTurn();
                 $formatter = new TeletextFormatter($currentGame);
                 $formattedText = $formatter->getFormat();
                 TeletextCommunicator::post($formattedText);
                 echo "Starting new round\n";
             }
         } else {
             // Users did not select anything...
             $currentGame->startNewTurn();
             echo "No move selected. Repeating turn.";
         }
     }
     $entityManager->flush();
     echo "Ended update\n";
 }