return $playerCards; } $deck = createDeck(); $num_players = 4; $num_cards_in_deck = count(createDeck());//find a function to count the # of elements in an array $num_cards_to_give_each_player = $num_cards_in_deck / $num_players; /* use a for loop to add the "dealt hands" to the $players array */ $players = array(); for($i=1; $i<=$num_players; $i++) { $playercards = dealCards($deck, $num_cards_to_give_each_player); $players[$i] = $playercards; } /* lets create a simple game each player will play a card and whoever has the highest value wins. if there are 2 cards played that have the same value everybody loses and that round is now a draw. store the results of each game in round_winners and also who won that round as the value. if the round is a draw store the value as DRAW use a loop to play each game until all oponents are out of cards Print out the array of all the rounds. if there was a draw the round should say DRAW
} if ($dealerValueTotal < $playerValueTotal && $dealerValueTotal <= 21) { $players[1][2] = dealCards($deck, 2); $dealerCard3 = $players[1][2][0]; $dealerValue3 = $validDeck[$dealerCard3]; $dealerValueTotal = $dealerValue1 + $dealerValue2 + $dealerValue3; } else { $winCondtion = true; if ($playerValueTotal > $dealerValueTotal) { $playerBank = $playerBank + 200; } else { $playerBank = $playerBank - 100; } } if ($dealerValueTotal < $playerValueTotal && $dealerValueTotal <= 21) { $players[1][3] = dealCards($deck, 2); $dealerCard4 = $players[1][3][0]; $dealerValue4 = $validDeck[$dealerCard4]; $dealerValueTotal = $dealerValue1 + $dealerValue2 + $dealerValue3 + $dealerValue4; } else { $winCondtion = true; if ($playerValueTotal > $dealerValueTotal) { $playerBank = $playerBank + 200; } else { $playerBank = $playerBank - 100; } } //} } var_dump($players); echo $dealerValueTotal;
</head> <body> <p> <?php /* * Lets bring in the deck code from the past example. (normal) create a function that will create a deck of cards, randomize it and then return the deck */ function createDeck() { return $deck; } /* We will now create a function to deal these cards to each user modify this function so that it returns the number of cards specified to the user also, it must modify the deck so that those cards are no longer available to be ditributed */ function dealCards(&$deck, $number_of_cards = 0) { } $player = dealCards($deck, 10); // player should now have 10 random cards in his hand ?> </p> </body> </html>
// $randomSuit = rand(0,3); $randomCard = rand(1,13); $deck[$ramdomcard][$ramdomcard]; $card = array_search($randomCard, $deck[$suit]); array_push($playerCards, $card); } var_dump ($playerCards); } $deck = createDeck(); $player = dealCards($deck,10); // player should now have 10 random cards in his hand foreach($deck as $suitName => $suitCards){ print $suitName . " - " . count($suitCards) . "<br />"; } ?> </p> </body> </html>
} $shuffled_deck = shuffle($deck); $card = array_shift($deck); } /* We will now create a function to deal these cards to each user modify this function so that it returns the number of cards specified to the user also, it must modify the deck so that those cards are no longer available to be ditributed */ function dealCards(&$deck, $number_of_cards) { createDeck(); for ($i = 0; $i < $number_of_cards; $i++) { $randsuit = rand(0, 3); $randcard = rand(0, 12); if (isset($setCards[$suit[$randsuit] . $card[$randcard]])) { $i--; continue; } return $number_of_cards; } } $player = dealCards($deck, 4); echo $player; ?> </p> </body> </html>
}else { $dealer_start_cards[1] = 1; } } }else { $dealer_sum = $dealer_start_cards[0] + $dealer_start_cards[1]; echo "Dealers Card sum ( not 21 ) :" . "<br />"; echo $dealer_sum . "<br />"; } die; if($player_sum == $dealer_sum || $player_sum < $dealer_sum) { // for($i = $player_sum; $) $player_card = dealCards($deck, 1); if($player_card[0] == 1) { if($player_sum == 10) { $players_bank = $players_bank + 200; }else { //choose random number of 1 or 11 } }else { $player_sum = $player_card[0] + $player_sum; if($player_sum > 21) { $player_sum = $player_sum - 100; } elseif($player_sum == 21) { $players_bank = $players_bank + 200;
<!DOCTYPE html> <html> <head> <title>unit4-2</title> </head> <body> <?php $rank = array('2', '3', '4', '5', '6', '7', '8', '9', 't', 'j', 'q', 'k', 'a'); $suit = array('c', 'd', 'h', 's'); $deck = array(52); $hand = array(5); createDeck(); dealCards(); printHand(); function createDeck() { global $deck; global $rank; global $suit; $this_card = 0; for ($this_suit = 0; $this_suit < count($suit); $this_suit++) { for ($this_rank = 0; $this_rank < count($rank); $this_rank++) { $deck[$this_card] = $rank[$this_rank] . $suit[$this_suit]; $this_card++; } } } function dealCards() { global $deck; global $hand;
function setNumPlayers($playerNum) { $db = connect_database(); $result = mysqli_query($db, "SELECT numPlayer FROM Envelope"); if ($result->num_rows <= 0) { global $totalMax; $totalMax = $playerNum; mysqli_query($db, "INSERT INTO Envelope (numPlayer) VALUES ('{$playerNum}')"); fullEnvelope(); dealCards($playerNum); } $db->close(); }