Solar Posted June 14, 2012 Share Posted June 14, 2012 Hey! I am attempting to create a fun game by using some of the communities code! The game is Higher, Lower, or the Same. I have modified the code to use a "Same" option but I just realized that it is useless unless I fix the problem. I want to be able to have 52 cards. These cards should not be doubles. For example; Your first card is a jack of clubs, I don't want that jack of clubs to show up again until after all 52 Cards are played. Then I want the deck to reshuffle so users can continue to play. Please tell me if I need to add more detail, I think this is understandable. Here is the source - <?php session_start(); ?> <link href="style.css" rel="stylesheet" type="text/css" /> <?php function deal (&$pack, $numhands, $cards_per_hand) { $hands = array(); if ($numhands*$cards_per_hand > 52) return $hands; $temp = array_slice ($pack, 0, $numhands*$cards_per_hand); $hands = array_chunk($temp, $cards_per_hand); return $hands; } $vals = array('1','2','3','4','5','6','7','8','9','10','j','q','k'); $suits = array('c','d','h','s'); $pack = array(); foreach ($vals as $v) { foreach ($suits as $s) { $pack[] = "$s$v"; $value[] = "$v"; $suit[] = "$s"; } } $card_picked = array_rand($pack); $card_number = $value[$card_picked]; echo "<img src=\"banner.png\">"; if (isset($_GET['sub'])) { switch($_GET['sub']) { case 'Higher': echo $card_picked > $_SESSION['card'] ? '<h1>Correct</h1>' : '<h1>Wrong</h1>'; break; case 'Lower': echo $card_picked < $_SESSION['card'] ? '<h1>Correct</h1>' : '<h1>Wrong</h1>'; break; case 'Same': echo $card_number == $_SESSION['number'] ? '<h1>Correct</h1>' : '<h1>Wrong</h1>'; break; } } $show_card = $pack[$card_picked]; $card_number = $value[$card_picked]; $card_suits = $suit[$card_picked]; $_SESSION['card'] = $card_picked; $_SESSION['number'] = $value[$card_picked]; ?> <form> <?php echo "<img src=\"cards/".$show_card.".gif\">"?><br><input type="submit" class="button" name="sub" value="Higher"> <input type="submit" class="button" name="sub" value="Lower"> <input type="submit" class="button" name="sub" value="Same"> </form> <?php //echo "$card_picked"; //echo "$card_number"; //echo "$card_suits"; ?> I was thinking would it be best to array the cards from a mysql table? To repeat my main question: How can I make the cards not double until the deck (52 cards) have been played, then re-shuffled? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/264195-help-cards-higher-or-lower/ Share on other sites More sharing options...
scootstah Posted June 14, 2012 Share Posted June 14, 2012 You need to remove a "dealt" card from the array of available cards. Look at unset. Quote Link to comment https://forums.phpfreaks.com/topic/264195-help-cards-higher-or-lower/#findComment-1353942 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.