Ejemplo n.º 1
0
 /**
  * Creating fight
  * @return bool
  */
 public function create()
 {
     if (!$this->validate()) {
         return false;
     }
     $transaction = Yii::$app->getDb()->beginTransaction();
     $saved = false;
     try {
         $fight = new Fight();
         if ($fight->save()) {
             $fightOwner = new FightUser(['user_id' => Yii::$app->getUser()->getIdentity()->cid, 'deck_id' => $this->deck_id, 'is_owner' => 1, 'fight_id' => $fight->id]);
             if ($fightOwner->save()) {
                 $saved = true;
                 $this->_fight = $fight;
             }
         }
     } catch (Exception $e) {
         $transaction->rollback();
     }
     if ($saved) {
         $transaction->commit();
     } else {
         $transaction->rollback();
     }
     return $saved;
 }
Ejemplo n.º 2
0
 /**
  * Load User
  * @return string
  * @throws HttpException
  */
 public function actionGetUser()
 {
     $fight = Fight::findOne(Yii::$app->request->post('fight'));
     if (!$fight) {
         throw new HttpException(404);
     }
     /*if(!$fight->check(Yii::$app->request->post('user'))){
     			throw new HttpException(403);
     		}*/
     $game = new Game();
     $player = new Player();
     $player->setIndex(2);
     $player->initialize($fight->user);
     $game->setPlayer2($player);
     return $this->render('player', ['game' => $game, 'player' => $player]);
 }
Ejemplo n.º 3
0
 public function actionStart()
 {
     $response = ['status' => 0, 'message' => '', 'redirect' => ''];
     $fight = Fight::findOne(Yii::$app->request->post('id'));
     if (!$fight) {
         throw new HttpException(404);
     }
     if (Fight::STATUS_NEW != $fight->status) {
         $response['message'] = 'Игра уже началась';
     } else {
         if ($fight->connect()) {
             $response['status'] = 1;
             $response['redirect'] = $fight->getUrl();
         }
     }
     return json_encode($response);
 }
Ejemplo n.º 4
0
 /**
  * Fight Action
  */
 public function actionFight()
 {
     $fight = Fight::findOne(Yii::$app->request->get('id'));
     if (!$fight) {
         throw new HttpException(404);
     }
     /*if(!$fight->check()){
           throw new HttpException(403);
       }*/
     return $this->render('fight', ['model' => $fight]);
 }
Ejemplo n.º 5
0
 /**
  * Get game instance
  * @param $id
  * @return Game
  */
 public function getFight($id)
 {
     if (!isset($this->fights[$id])) {
         $game = new Game();
         $game->setFight(Fight::find()->where('id = :id', [':id' => $id])->one());
         $game->setManager($this);
         $this->fights[$id] = $game;
         unset($game);
     }
     return $this->fights[$id];
 }