コード例 #1
0
ファイル: JoinGameCommand.php プロジェクト: Tomeno/lulcobang
 protected function run()
 {
     if ($this->check === self::OK) {
         $playersCount = GameUtils::getPosition($this->game);
         $params = array('game' => $this->game['id'], 'user' => $this->loggedUser['id'], 'seat' => GameUtils::getSeatOnPosition($playersCount));
         // TODO use repository
         DB::insert(DB_PREFIX . 'player', $params);
     }
 }
コード例 #2
0
 protected function run()
 {
     if ($this->check == self::OK) {
         $colorRepository = new ColorRepository();
         $count = $colorRepository->getCountAll();
         $randomColor = mt_rand(1, $count);
         $userParams = array('username' => 'AI-' . str_pad(mt_rand(0, 999), 3, 0, STR_PAD_LEFT), 'color' => $randomColor);
         $userRepository = new UserRepository();
         $newUser = $userRepository->getOneByUsername($userParams['username']);
         if (!$newUser) {
             $newUser = new User($userParams);
             $newUser = $newUser->save(TRUE);
         }
         $playersCount = GameUtils::getPosition($this->game);
         $strategyRepository = new AiStrategyRepository();
         $strategyRepository->addOrderBy(array('RAND()' => ''));
         $strategy = $strategyRepository->getOneBy();
         $params = array('game' => $this->game['id'], 'user' => $newUser['id'], 'seat' => GameUtils::getSeatOnPosition($playersCount), 'ai_strategy' => $strategy['id']);
         $player = new Player($params);
         $player->save();
     }
 }