Example #1
0
 private function post($view, GameAction $action, $char = null)
 {
     $content = $this->twig->render("::" . $view . ".text.twig", array('game' => $action->getGame(), 'action' => $action, 'char' => $char));
     $payload = new ChatPostMessagePayload();
     $payload->setChannel("#" . $action->getChannelName());
     $payload->setText($content);
     $payload->setUsername("Hangbot");
     $response = $this->slack->send($payload);
     return $response;
 }
Example #2
0
 /**
  * @param $command string command text given in slash command
  * @param $user string user
  * @param $channel string channel where command is given
  * @return string Message to be returned
  * @throws \InvalidArgumentException Exception message to be returned
  */
 public function execute($command, GameAction $action)
 {
     $parts = explode(" ", $command);
     $cmd = array_shift($parts);
     $action->setGame($this->gm->getGameInProgress($action->getChannelId()));
     switch ($cmd) {
         case 'start':
             // start {word} {hint}
             if (count($parts) == 0) {
                 throw new \InvalidArgumentException("You must specify a word");
             }
             $word = array_shift($parts);
             if (count($parts) > 0) {
                 $hint = implode(" ", $parts);
             } else {
                 $hint = null;
             }
             $this->gm->startGame($action, $word, $hint);
             return "Game has started";
         case 'help':
             $this->gm->showHelp($action);
             return "";
         case 'hint':
             // hint {hint}
             if (count($parts) > 0) {
                 $hint = implode(" ", $parts);
                 $this->gm->changeHint($action, $hint);
                 return "Hint is changed";
             } else {
                 throw new \InvalidArgumentException("Please provide a hint");
             }
         case 'guess':
             // guess {char or word}
             if (count($parts) > 0) {
                 $word = array_shift($parts);
                 if (strlen($word) == 1) {
                     $this->gm->guessCharacter($action, $word);
                 } else {
                     $this->gm->guessWord($action, $word);
                 }
                 return "";
             } else {
                 throw new \InvalidArgumentException("Please provide a character or guess the entire word");
             }
         case 'abort':
             // abort
             $this->gm->abort($action);
             return "Game aborted";
         case 'highscore':
             return "This is not implemented yet, sorry!";
         default:
             throw new \InvalidArgumentException("Invalid command given");
     }
 }
Example #3
0
 public function abort(GameAction $action)
 {
     $game = $action->getGame();
     if (!$game) {
         throw new \InvalidArgumentException("No game in progress");
     }
     if ($game->getUserStarted() !== $action->getPlayerId()) {
         throw new \InvalidArgumentException("You are not the game master!");
     }
     $game->abort();
     $this->slack->postAbort($action);
     $this->em->flush();
 }