Ejemplo n.º 1
0
 /**
  * @param User $user
  * @param Bets $bets
  * @param $bet
  * @param $free_bet
  * @param int $split
  * @return bool|Player
  */
 public function addPlayer(User $user, Bets $bets, $bet, $free_bet, $split = 0)
 {
     if (!$this->isGameStarted()) {
         $Player = new Player();
         $Player->construct($user, new Hand(), new PlayerState(PlayerState::Join), $this->getNumberOfPlayers(), $bet, $free_bet, NULL, NULL, $split);
         $Player->Hand->addCard($this->Deck->dealCard());
         $Player->Hand->addCard($this->Deck->dealCard());
         if ($Player->Hand->isBlackjack()) {
             $Player->State = new PlayerState(PlayerState::BlackJack);
         }
         $this->Players[] = $Player;
         $this->SQL->insert_player($this->game_id, $Player);
         if ($bet > 0 && !$free_bet) {
             $bets->payBank($Player, new TransactionType(TransactionType::BlackjackBet));
         }
         $Player->bet = round($bet, 2);
         return $Player;
     } elseif ($split == 2) {
         foreach ($this->Players as $Player) {
             if ($Player->player_no > $this->getCurrentPlayer()->player_no) {
                 $Player->player_no++;
                 $this->savePlayer($Player);
             }
         }
         $Player = new Player();
         $Player->construct($user, new Hand(), new PlayerState(PlayerState::Join), $this->getCurrentPlayer()->player_no + 1, $bet, $free_bet, NULL, NULL, 2);
         $Card = $this->getCurrentPlayer()->Hand->Cards[1];
         $this->getCurrentPlayer()->Hand->removeCard($Card);
         $Player->Hand->addCard($Card);
         $Player->Hand->addCard($this->Deck->dealCard());
         if ($Player->Hand->isBlackjack()) {
             $Player->State = new PlayerState(PlayerState::BlackJack);
         }
         $this->Players[] = $Player;
         $this->SQL->insert_player($this->game_id, $Player);
         if ($bet > 0) {
             $bets->payBank($Player, new TransactionType(TransactionType::BlackjackBet));
         }
         $Player->bet = round($bet, 2);
         return $Player;
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * @param PlayerMove $Move
  * @return bool
  */
 private function processPlayerMove(PlayerMove $Move)
 {
     if ($this->Game->isGameStarted()) {
         $player = $this->Game->getCurrentPlayer();
         if ($this->Game->getCurrentPlayer()->user->user_id == $this->user->user_id && $Move != PlayerMove::JoinGame && $Move != PlayerMove::StartGame) {
             $this->processTurn($Move);
         } elseif ($player->user->user_id != $this->user->user_id && strtotime("-5 minutes") > strtotime($player->last_move_time)) {
             $this->user->user_id = $player->user->user_id;
             $this->Talk->turn_expired($player);
             $this->processTurn($this->newPlayerMove(PlayerMove::DefaultMove));
         } elseif ($Move == PlayerMove::JoinGame || $Move == PlayerMove::StartGame) {
             $this->Talk->game_status($this->Game);
         }
     } elseif (!$this->Game->isPlayerInGame($this->user->user_id)) {
         if ($Move == PlayerMove::JoinGame) {
             if (!$this->Bets->checkPlayerBet($this->Game, $this->user, $this->Game->Dealer->user, $this->bet)) {
                 return false;
             }
             $this->bet = $this->Bets->bet;
             $this->free_bet = $this->Bets->free_bet;
             $player = $this->Game->addPlayer($this->user, $this->Bets, $this->bet, $this->free_bet);
             $this->Talk->join_game($player);
         } elseif ($Move == PlayerMove::StartGame) {
             if (!$this->Bets->checkPlayerBet($this->Game, $this->user, $this->Game->Dealer->user, $this->bet)) {
                 return false;
             }
             $this->bet = $this->Bets->bet;
             $this->free_bet = $this->Bets->free_bet;
             $this->Game->addPlayer($this->user, $this->Bets, $this->bet, $this->free_bet);
             $this->Game->startGame();
             $this->Game->saveGame();
             $this->Talk->start_game($this->Game);
             if ($this->Game->areAllPlayersDone()) {
                 $this->finaliseGame();
                 $this->Game->endGame();
             }
         }
     } elseif ($this->Game->isPlayerInGame($this->user->user_id)) {
         if ($Move == PlayerMove::StartGame) {
             $this->Game->startGame();
             $this->Game->saveGame();
             $this->Talk->start_game($this->Game);
             if ($this->Game->areAllPlayersDone()) {
                 $this->finaliseGame();
                 $this->Game->endGame();
             }
         } elseif ($Move == PlayerMove::QuitGame) {
             $this->Game->endGame();
         } elseif ($Move != PlayerMove::JoinGame) {
             $this->Talk->pre_game_status($this->Game);
         }
     }
     return true;
 }