public function run(\IQU\DataSource\HttpRequest $request) { $letter = $request->getParameter('letter'); $return = ['illegalLetter' => 0, 'isFinish' => 0, 'isWin' => 0, 'word' => $this->hangmanService->getWord(), 'triesLeft' => $this->hangmanService->getCountOfTries()]; if (!$this->validationHangmanService->isAcceptableLetter($letter)) { $return['illegalLetter'] = 1; return $return; } if (!$this->hangmanService->openLetter($letter)) { $this->hangmanService->decreaseCountOfTries(); } return ['illegalLetter' => 0, 'isFinish' => $this->hangmanService->isEndOfTheGame(), 'isWin' => $this->hangmanService->isWordFound(), 'word' => $this->hangmanService->getWord(), 'triesLeft' => $this->hangmanService->getCountOfTries()]; }
/** * @return bool */ public function isWordFound() { $word = $this->storeService->getWord(); $freq = []; $len = strlen($word); for ($i = 0; $i < $len; $i++) { $letter = $word[$i]; if (empty($letter)) { continue; } if ($this->validationService->isAcceptableLetter($letter) && !in_array($letter, $freq)) { $freq[] = $letter; } } return count($freq) == count($this->storeService->getRightLetter()); }