/** * Create a new Card Deck and two new player hands from that deck as an array * * @return array An array consisting of the Dealer Hand, Player Hand, and remainder of Deck */ function getNewHand() { $deck = getCardDeck(); $dealer = array(drawCard($deck), drawCard($deck)); $player = array(drawCard($deck), drawCard($deck)); return array($dealer, $player, $deck); }
function getGameOn($deck, $dealer, $player) { if (getHandTotal($player) < 21) { fwrite(STDOUT, '(H)it or (S)tay?'); $response = trim(strtoupper(fgets(STDIN))); if ($response == 'H') { drawCard($player, $deck); sleep(1); echoHand($player, 'Player'); sleep(1); return getGameOn($deck, $dealer, $player); } elseif ($response == 'S') { sleep(1); whoWins($deck, $dealer, $player); } elseif ($response != 'S' || $response != 'H') { getGameOn($deck, $dealer, $player); return; } } if (getHandTotal($player) == 21) { echo 'You got 21!' . PHP_EOL; sleep(1); playAgain($deck, $dealer, $player); } if (getHandTotal($player) > 21) { echo 'It appears you have busted. ' . PHP_EOL; sleep(1); playAgain($deck, $dealer, $player); return; } }
function drawCard() { drawCard($this->id, $this->deck, $this->user); }
function drawStartingHand($id) { $player = getGamePlayers($id); $deck = getPlayerDecks($id); for ($i = 0; $i < 5; $i++) { drawCard($id, $deck[0], $player[0]); drawCard($id, $deck[1], $player[1]); } }
<?php session_start(); include 'functions.php'; if (isset($_POST['hit'])) { $deck = createDeck(); $hand = drawCard($deck); $_SESSION["player"] = $hand['player']; $_SESSION['dealer'] = $hand['dealer']; $hand_player = $_SESSION["player"]; $hand_dealer = $_SESSION['dealer']; print_r($hand_player) . '<br>'; echo "<h3>Cards of the player</h3><br>"; foreach ($hand_player as $key => $card) { $img = $card['card'] . $card['face'] . '.jpg'; echo $img; echo "<img src =\"cards/{$img}\">"; } echo "<h3>Cards of the dealer</h3><br>"; foreach ($hand_dealer as $key => $card) { $img = $card['card'] . $card['face'] . '.jpg'; echo $img; echo "<img src =\"cards/{$img}\">"; } echo '<br>'; print_r($hand_dealer) . '<br>'; } else { if (isset($_POST['stay'])) { echo "Hello3"; } else { if (isset($_POST['finish'])) {