Beispiel #1
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;
 }
Beispiel #2
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);
     }
 }