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; } }
function commandRouter($action) { switch ($action) { case 'login': loginUser(); break; case 'createUser': createUser(); break; case 'getUser': getUser(); break; case 'deleteUser': deleteUser(); break; case 'updateUser': updateUser(); break; case 'addInv': addToInv(); break; case 'subInv': subFromInv(); break; case 'getInv': getInventory(); break; case 'getDecks': getDecks(); break; case 'createDeck': createDeck(); break; case 'updateDeck': updateDeck(); break; case 'deleteDeck': deleteDeck(); break; default: break; } }
<?php function createDeck() { $colors = array("Spades", "Hearts", "Clubs", "Diamonds"); $cards = array("Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace"); //function createDeck - it will create a deck of 52 cards. $deck = array(); foreach ($colors as $color) { foreach ($cards as $card) { $deck[] = array("card" => $card, "color" => $color); } } return $deck; } print_r(createDeck());
$value = $deck[$key]; if(isset($deck[$key])) { $playerCards[$key] = $value; unset($deck[$key]); } } 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
foreach ($suits as $suit) { $i = "{$face} of {$suit}"; $deck[$i] = $face; } } $keys = array_keys($deck); ////code obtained from array shuffle documentation shuffle($keys); foreach ($keys as $key) { $new[$key] = $deck[$key]; } $deck = $new; //true;///not sure what this is for but seems to work either way return $deck; } $deck = createDeck(); var_dump($deck); echo "<br/>"; echo "<br/>"; echo "<br/>"; /* 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) { $newCard = array_rand($deck, $number_of_cards); $dealt = array(); for ($i = 0; $i < count($newCard); $i++) { array_push($dealt, $newCard[$i]);
<?php $servername = "localhost"; $username = "******"; $password = "******"; $event_deck = new deck(); $opp_deck = new deck(); // Create connection $conn = new mysqli($servername, $username, $password, "jordanp0_gameofbiz"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } function createDeck($tableName, $objectName, $column1, $column2) { global $conn; $sql = "SELECT {$column1}, {$column2} FROM {$tableName}"; $result = $conn->query($sql); $return = array(); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $return[] = new $objectName($row[$column1], $row[$column2]); } return $return; } } $event_deck = createDeck('eventCard', 'event_card', 'Description', 'profit'); $opp_deck = createDeck('oppCard', 'opp_card', 'Description', 'profit');
/** * Initializes a new round */ function init() { if (!$_SESSION['acceptNewRound']) { return; } else { $_SESSION['acceptNewRound'] = False; } //Make sure player is not trying to use money it doesn't have if ($_SESSION['playerMoney'] < $_POST['bet']) { $_SESSION['newRound'] = False; $_SESSION['playing'] = False; $_SESSION['blackjackError'] = trans('outOfMoney'); $_SESSION['acceptNewRound'] = True; redirectTo($_SESSION['index']); exit; } $_SESSION['blackjackFactor'] = 2.5; $_SESSION['normalFactor'] = 2; $_SESSION['charlieFactor'] = 2; $_SESSION['deck'] = []; //Cards left in the deck //Initializes only one array, so that you can count this array to know number of splits $_SESSION['playerCards'] = [[]]; //Cards player has received $_SESSION['dealerCards'] = []; //Cards dealer has received $_SESSION['dealerCardsCalculated'] = 0; //How many cards have already been calculated $_SESSION['playerAce'] = [False]; //Player has ace counting as 11 $_SESSION['dealerAce'] = False; //Dealer has ace counting as 11 //Can only have blackjack on first hand $_SESSION['playerBlackjack'] = False; //Player has blackjack or not $_SESSION['dealerBlackjack'] = False; //Dealer has blackjack or not //Hand has charlie or not $_SESSION['charlie'] = [False]; $_SESSION['splitAvailable'] = [False]; //Player can split $_SESSION['aceSplit'] = [False]; $_SESSION['handDone'] = [False]; //Keeps track of which hands are done $_SESSION['endGame'] = False; //Game is ending $_SESSION['playerSum'] = [0]; //Keeps track of sum of every hand $_SESSION['dealerSum'] = 0; //Dealer sum $_SESSION['bets'][0] = $_POST['bet']; $_SESSION['originalBet'] = $_POST['bet']; //Store the original bet, in case of doubling $hand = 0; $_SESSION['currentHand'] = $hand; //Make sure bet is not out of bounds if ($_SESSION['bets'][$hand] < 100) { $_SESSION['bets'][$hand] = 100; } elseif ($_SESSION['bets'][$hand] > $_SESSION['maxbet']) { $_SESSION['bets'][$hand] = $_SESSION['maxbet']; } //Start round by taking money from player adjustMoney($hand); createDeck(); playerDraw(); dealerDraw(); calculate(); $_SESSION['newRound'] = False; if ($_SESSION['dealerSum'] === 21) { $_SESSION['dealerBlackjack'] = True; } //Player got blackjack, end the game if ($_SESSION['playerSum'][$hand] === 21) { $_SESSION['playerBlackjack'] = True; } if ($_SESSION['dealerBlackjack'] || $_SESSION['playerBlackjack']) { $_SESSION['endGame'] = True; $_SESSION['handDone'][$hand] = True; printCards(); endOfGame(); } else { printCards(); //Prevents refresh of page to instantly start a new game redirectTo($_SESSION['index'] . '#cards'); } }
<!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;