Exemplo n.º 1
0
 /**
  * Checks if a letter exists in a word and handles the updating of the Game entity
  * @param $char
  * @param \Houdtbaar\HangmanBundle\Entity\Game $game
  * @return $char
  */
 public function checkLetter($char, Game $game)
 {
     $wordInLetters = $game->getWordInLetters();
     // check if input is a string
     if (preg_match('/^[a-z]$/', $char) === 0) {
         return null;
     }
     if (in_array(strtolower($char), $wordInLetters) === true) {
         $game->addGuessedLetters($char);
         $game->addTriedLetters($char);
     } else {
         $game->addTriedLetters($char);
     }
     $game->setDottedWord();
     $game->setTriesLeft();
     $game->setStatus();
     $this->saveGame($game);
     return $char;
 }