Example #1
0
 /**
  * Advance game, actioning Phase related actions and decisions
  * @param Game $game
  * @return Decision
  */
 protected function advanceGame(Game $game)
 {
     $em = $this->getDoctrine()->getManager();
     // Loop until we have a decision point to go back to the user with
     while (!$game->getDecision()) {
         $a = $game->getCurrentAction();
         if ($a) {
             if ($a->getSubAction()) {
                 LogFactory::startLog($game);
                 if ($a->hasDecision($game)) {
                     $game->setDecision();
                 } else {
                     // Execute also advances subAction
                     $a->execute($game, $this);
                 }
                 LogFactory::completeLog($game->getLog());
             } else {
                 $a->setNextSubAction($game);
             }
         } else {
             // No action so advance Phase to get one
             $game->advancePhase();
         }
         $em->flush();
     }
     return $game->getDecision();
 }