예제 #1
0
 /**
  * @param Hand $hand
  * @param array $context
  * @param Deck $deck
  * @return \Cards\Card
  */
 public function takeMove(Hand $hand, $context, Deck $deck = null)
 {
     $hand->showAllCards();
     while ($this->countCards($hand) < 17) {
         $hand->giveCard($deck->drawCard());
     }
 }
예제 #2
0
 /**
  * @param Hand $hand
  * @param array (of card arrays) $context
  * @param Deck $deck
  * @return \Cards\Card
  */
 public function takeMove(Hand $hand, $context, Deck $deck = null)
 {
     $dealersHand = $context;
     /* @var Hand $dealersHand */
     $this->printHand($dealersHand, $hand);
     while ("H\n" == fread(STDIN, 2) || $this->countCards($hand) <= 21) {
         $card = $deck->drawCard();
         $hand->giveCard($card);
         $this->printHand($dealersHand, $hand);
         echo "Hit?\n";
     }
 }
예제 #3
0
 public function __construct()
 {
     $dealerStrategy = new Dealer();
     $dealerPlayer = new Player($dealerStrategy);
     $userStrategy = new User();
     $userPlayer = new Player($userStrategy);
     $round = new Round(array($userPlayer, $dealerPlayer));
     $deck = new Deck();
     $deck->addPack();
     $deck->shuffle();
     /**
      * Deal
      */
     $dealerPlayer->getHand()->giveCard($deck->drawCard());
     $dealerPlayer->getHand()->giveCard($deck->drawCard()->hideCard());
     $userPlayer->getHand()->giveCard($deck->drawCard());
     $userPlayer->getHand()->giveCard($deck->drawCard());
     /**
      * Player
      */
     while ($round->newRound()) {
         echo "Starting new round\n";
         while ($player = $round->nextPlayer()) {
             echo "Start of turn\n";
             /* @var Player $player */
             $player->takeMove($dealerPlayer->getHand(), $deck);
             $player->finished();
         }
     }
     $this->printHand($dealerPlayer->getHand(), $userPlayer->getHand());
 }