Exemple #1
0
 /**
  * Deals cards to players based on hand size,
  * will deal entire deck if handSize is 0. Has scope for
  * dealing different sized hands as required
  *
  * @param int $handSize
  */
 protected function deal($handSize = 0)
 {
     Talk::say('Dealing...');
     if ($handSize == 0) {
         // If handSize is 0 then we'll deal all the cards to all players
         $counter = floor($this->deck->undealtCount() / count($this->players));
     } else {
         if ($this->deck->undealtCount() >= count($this->players) * $handSize) {
             // Else if theres enough cards we'll deal the appropriate handSize
             $counter = $handSize;
         } else {
             // But if theres not enough cards we'll exit
             $counter = 0;
         }
     }
     // If we've got players
     if (!empty($this->players)) {
         // And the counter allows it
         while ($counter > 0) {
             // Deal a card to each player
             foreach ($this->players as $player) {
                 $player->takeCard($this->deck->deal());
             }
             // Decrement the counter
             $counter--;
         }
     }
 }
Exemple #2
0
        }
    }
    public function getHandValue()
    {
        $panier = 0;
        foreach ($this->hand as $card) {
            $panier += $card->getValue();
        }
        return $panier;
    }
}
class Bank extends Player
{
    public function __construct()
    {
        parent::__construct("Banque");
    }
}
//SCENARIO 1
$deck = new Deck();
$deck->shuffle();
$bank = new Bank();
$bank->take($deck->deal(2));
while ($bank->getHandValue() < 16) {
    $bank->take($deck->deal(1));
}
if ($bank->getHandValue() > 21) {
    echo "La banque perd " . $bank->getHandValue();
} else {
    echo "La banque a " . $bank->getHandValue();
}
Exemple #3
0
<?php

session_start();
require_once "classes/indexClasses.php";
require_once "classes/cardClasses.php";
$deck = new Deck();
$deck->shuffle();
$player = new Bank();
$player->take($deck->deal(2));
//Le joueur se voit distribué 2 cartes
echo "Tu as tiré 2 cartes et tu as " . $player->getHandValue();
if (isset($_POST['choice'])) {
    while ($player->getHandValue() < 17) {
        $player->take($deck->deal(1));
    }
    if ($player->getHandValue() > 21) {
        echo "<br>Tu as perdu avec " . $player->getHandValue();
        session_unset();
    } else {
        echo "<br>Tu as gagné avec " . $player->getHandValue();
        session_unset();
    }
}
if (isset($_POST['pass'])) {
    $deck = new Deck();
    $deck->shuffle();
}
if (isset($_POST['reset'])) {
    session_unset();
    session_destroy();
    //header("Location:/");