예제 #1
0
 public function startGame(GameAction $action, $word, $hint = null)
 {
     if ($action->getGame()) {
         throw new \InvalidArgumentException("A game is already in progress");
     }
     $game = new Game($action->getPlayerId(), $action->getPlayerName(), $action->getChannelId(), $word);
     if ($hint) {
         $game->setHint($hint);
     }
     $action->setGame($game);
     $this->slack->postStarting($action);
     $this->em->persist($game);
     $this->em->flush();
     return $game;
 }
예제 #2
0
 public function getHangmanWord(Game $game)
 {
     $res = "";
     if ($game->isLost() || $game->isWon()) {
         return implode(" ", str_split($game->getWord()));
     }
     $chars = str_split($game->getWord());
     $guesses = $game->getCharacters();
     foreach ($chars as $char) {
         if (in_array($char, $guesses)) {
             $res .= $char;
         } else {
             $res .= "_";
         }
     }
     return "`" . implode(" ", str_split($res)) . "`";
 }