Jump to content

[HELP] Cards Higher or Lower


Solar

Recommended Posts

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.