Exemplo n.º 1
0
 protected function analyzeTurns()
 {
     $turns = $this->game->getTurnsOf($this->player);
     $bestScore = 0;
     $bestAverage = 0.0;
     $totalShots = 0;
     $totalScore = 0;
     $this->shots = array();
     foreach ($turns as $turn) {
         if ($turn->isVoid()) {
             continue;
         }
         $this->shots = array_merge($this->shots, $turn->getArrows());
         if ($bestScore < $turn->getTotalScore()) {
             $bestScore = $turn->getTotalScore();
         }
         if ($bestAverage < $turn->getAverageScore()) {
             $bestAverage = $turn->getAverageScore();
         }
         $totalShots += 3;
         $totalScore += $turn->getTotalScore();
     }
     $overallAverage = count($turns) > 0 ? $totalScore / count($turns) : 0;
     $this->stats->turns = count($turns);
     $this->stats->turnBestAverage = $bestAverage;
     $this->stats->turnBestScore = $bestScore;
     $this->stats->turnAverage = $overallAverage;
 }
Exemplo n.º 2
0
 /**
  * check if game has been won by either player
  *
  * returns a player if game is over (the winner is returned)
  * else returns null, game is not over yet
  *
  * @param Game $game
  *
  * @return Player|null the winner or null if ame is not over
  *
  * @throws \Exception
  */
 protected function checkForWinner(Game $game)
 {
     $gameMode = $game->getGameMode();
     switch ($gameMode->getMode()) {
         case GameMode::AHEAD:
             $player1count = $game->getLegsWonPlayer1() - $game->getLegsWonPlayer2();
             $player2count = $game->getLegsWonPlayer2() - $game->getLegsWonPlayer1();
             break;
         case GameMode::FIRST_TO:
             $player1count = $game->getLegsWonPlayer1();
             $player2count = $game->getLegsWonPlayer2();
             break;
         default:
             throw new \Exception('invalid game mode');
             break;
     }
     if ($player1count == $gameMode->getCount()) {
         return $game->getPlayer1();
     } elseif ($player2count == $gameMode->getCount()) {
         return $game->getPlayer2();
     }
     return null;
 }
Exemplo n.º 3
0
 /**
  * create leg-gears for "current-leg"
  *
  * if the last leg of the provided games is not closed, it is used.
  * else a new leg is created, persisted and used for the leg-gears.
  *
  * it is the responsibility of the caller to make sure the game actually needs
  * additional legs.
  *
  * @param Game $game
  *
  * @return LegGearsInterface
  */
 public function create(Game $game)
 {
     $currentLeg = null;
     $lastLeg = $game->getLegs()->last();
     if ($lastLeg instanceof Leg && !$lastLeg->isClosed()) {
         $currentLeg = $lastLeg;
     }
     if (null === $currentLeg) {
         $currentLeg = new Leg($game);
         $this->entityManager->persist($currentLeg);
     }
     $roundSetup = $game->getGroup()->getRound()->getSetup();
     $legMode = $roundSetup->getLegMode();
     if (in_array($legMode->getMode(), LegGearsSimple::getSupportedModes())) {
         $gears = new LegGearsSimple($currentLeg);
     } else {
         throw new \InvalidArgumentException('can not create leg-gears for ' . $legMode->getMode());
     }
     $gears->setLogger($this->logger);
     $this->eventDispatcher->addSubscriber($gears);
     $this->entityManager->flush();
     return $gears;
 }
Exemplo n.º 4
0
 public function __construct(Game $game)
 {
     $this->game = $game;
     $this->created = new \DateTime();
     $game->addLeg($this);
 }
Exemplo n.º 5
0
 /**
  * check if the provided game completes the associated group and proceed accordingly
  *
  * @param Game $game
  * @param EventDispatcherInterface $dispatcher
  */
 protected function handleGameCompletesGroup(Game $game, EventDispatcherInterface $dispatcher)
 {
     $group = $game->getGroup();
     if ($group->isClosed()) {
         $this->log('handleGameCompletesGroup, GROUP COMPLETE!');
         $groupCompletedEvent = new GroupEvent();
         $groupCompletedEvent->setGroup($group);
         $dispatcher->dispatch(EngineEvents::GROUP_COMPLETED, $groupCompletedEvent);
         $this->handleGroupCompletesRound($group, $dispatcher);
     }
 }