Task: to make a game supported by various devices. The game must support the following types:

  1. Text game (only text and images, minimum number of JS)
  2. Dynamic game (text, pictures and full JS)
  3. Native app for iOS and Android. Server: PHP (Yii2 framework) + Mysql + Nginx Client: CSS + JS + HTML for types 1, 2 and Swift, Java for type 3

How to implement a project with minimal time?

At the moment I see it this way: on the server I am doing the game API, on the client I am outputting the data. Suppose we have a location - Arena.

Arena API: game.ru/api/arena

Methods: game.ru/api/arena/attack - conducting the battle game.ru/api/arena/change-target - change the enemy game.ru/api/arena/location - get actual location data (opponents, number of battles held , the current enemy, and TP)

For a text game and a dynamic game, in the yii2 controller of the arena module, send requests for the necessary methods and transfer information to the view. There it can be displayed for a specific type (static or dynamic). For a native game, send a request to the server API from the corresponding controller, retrieve data and send it to the view. Code

Class ArenaLocation extends Object { /** * Метод обработки атаки (снижает здоровье противнику и игроку и тп) * @return bool **/ public function attack(){} /** * Метод смены противника * @return bool **/ public function changeTarget(){} /** * Метод возвращает объект текущего противника * @return object Target **/ public function getTarget(){} /** * Метод возвращает объект игрока * @return object Player **/ public function getPlayer(){} /** * Метод возвращает JSON кодированные данные Арены **/ public function getJsonLocation() { return json_encode('...'); } } 

Arena API Class

 class ArenaApi extends ApiController { /** * @var object ArenaLocation */ private $arenaLocation; /** * Атака противника */ public function actionAttack() { $location = $this->getArenaLocation(); $location->attack(); $this->actionLocation(); } /** * Смена противника */ public function actionChangeTarget() { $location = $this->getArenaLocation(); $location->changeTarget(); $this->actionLocation(); } /** * Возвращает данные об арене */ public function actionLocation() { $location = $this->getArenaLocation(); header('Content-Type: application/json'); echo $location->getJsonLocation(); } /** * @return object ArenaLocation */ private function getArenaLocation() { return $this->arenaLocation = $this->arenaLocation === null ? new ArenaLocation() : $this->arenaLocation; } } 

Is this approach correct?

    0