/** * Initialize all the property controller needed. */ protected function initialize() { $this->game = new Game(); $this->request = new Request(); $this->battleshipView = new View\Battleship(); $this->game->initialize(); $this->request->createForm('/index.php'); }
/** * Render the output view when you finish the game * * @param Game $game */ protected function renderGameFinished(Game $game) { $viewFlashMessage = new ViewFlashMessage(); $view = new MainView(); $flashMessage = $game->getFlashMessage(); $message = "Well done! You complete the game in {$game->getShots()} shots"; $flashMessage->customNotification($message); $viewFlashMessage->prepare($flashMessage); $view->addViewObject($viewFlashMessage); $view->render(); }
/** * Add new games to db and game catalog * * @param \model\Game $credential * @param \model\IListener $listener * @return bool */ public function add(\model\Game $credential, \model\IListener $listener) { try { $random = rand(0, pow(10, 5)) . '-'; // 5 digit random number to prefix game and img name $gameDirectory = "../public/games/"; // path to game directory $imgDirectory = "../public/images/"; // path to image directory $title = $credential->getTitle(); $gameFile = $random . $credential->getGameFile()["name"]; $imgFile = $random . $credential->getImage()["name"]; $targetFile = $gameDirectory . $gameFile; $targetImg = $imgDirectory . $imgFile; // Move img and game file to the given directory move_uploaded_file($credential->getGameFile()["tmp_name"], $targetFile); move_uploaded_file($credential->getImage()["tmp_name"], $targetImg); $records = $this->db; $records->query('INSERT INTO game (title, game, img) VALUES (:title, :game, :img)'); $records->bind(':title', $title); $records->bind(':game', $gameFile); $records->bind(':img', $imgFile); $records->execute(); return true; } catch (\Exception $e) { $listener->errorListener("AddGameDal::CouldNotAddGameException"); } }