Exemple #1
0
 /**
  * Process turn
  *
  * @param  string $action
  * @return void
  */
 public function turn($action)
 {
     switch ($action) {
         case self::ACTION_TWIST:
             $this->game->addCard($this->player);
             if ($this->player->getScores() >= self::MAX_SCORES_PLAYER) {
                 // do nothing if the player has lost or won
                 $this->dealer->complete();
             } else {
                 // or deal a new card
                 $this->game->addCard($this->dealer);
             }
             break;
         case self::ACTION_STICK:
         default:
             $this->player->complete();
             // the player stopped, so lets get the missing cards
             while (!$this->dealer->isCompleted()) {
                 $this->game->addCard($this->dealer);
             }
             break;
     }
     // save current state
     $this->save();
     // finish the game session and add the result to the history and statistic
     if (!$this->isContinues()) {
         return $this->finish();
     }
     return $this->getState();
 }