Ejemplo n.º 1
0
 protected function analyzeLegs()
 {
     $bestLegScore = 0;
     $legLeastShots = null;
     foreach ($this->game->getLegs() as $leg) {
         $score = $leg->getScoreOf($this->player);
         if ($score > $bestLegScore) {
             $bestLegScore = $score;
         }
         if ($leg->getWinner() == $this->player) {
             $shots = $leg->getCountShotsOf($this->player);
             if (null === $legLeastShots || $shots < $legLeastShots) {
                 $legLeastShots = $shots;
             }
         }
     }
     $this->stats->legBestScore = $bestLegScore;
     $this->stats->legLeastShots = $legLeastShots;
 }
Ejemplo n.º 2
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;
 }