/** * Основной метод игры * * @return string * @throws \Exception */ public function indexAction() { $tel = $_REQUEST['tel']; $msg = strtolower($_REQUEST['msg']); if (empty($tel) || empty($msg)) { throw new \Exception("Invalid http request", 404); } /** @var $user User*/ $user = User::getByLogin($tel); /** @var $game Game */ $game = Game::getByUserId($user->id); if (empty($game)) { throw new \Exception("Game not initialized", 404); } /** @var $results Array результаты ответа*/ $results = BullsCow::processAnswer($game, $msg); return $this->render('index/index.php', array('results' => $results)); }
/** * Начинает новую игру * * @param $user_id * @return Game */ public static function initGame($user_id) { return Game::create($user_id, static::prepareTask()); }