poker dice php - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

poker dice php

Garrett85Garrett85 Posts: 168Member
I can't find the an error is this php code. It's probably somewhere in the second half of the code because I loaded the web page before and it worked fine. Note that the program is not finished.

[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



poker dice


body
{
background: green;
color: tan;
}




Poker Dice


<?php

//check to see if this is first time here
if(empty($cash))
{
$cash = 100;
} // end if

rollDice();

if($secondRoll == true)
{
print "<h2>Second Roll
";
$secondRoll = false;
evaluate();
}

else
{
print "

First Roll

";
$secondRoll = true;
} // end if/else

printStuff();

function rollDice()
{
global $die, $secondRoll, $keepIt;

print "";

for($i = 0; $i < 5; $i++)
{
if($keepIt[$i] == "")
{
$die[$i] = rand(1,6);
}

else
{
$die[$i] = $keepIt[$i];
} // end else

$theFile = "die" . $die[$i] . ".jpg";

// print out die images
print<<< HERE
<td>


HERE;

//print out a checkbox on first roll only
if($secondRoll == false)
{
print <<<HERE

<input type = "checkbox"
name = "keepIt[$i]"
value = $die[$i]>


HERE;
} // end if
} // end for loop

//print out submit button and end of table
print <<<HERE
</tr>







HERE;
} // end rollDice()

if($keepIt[$i] == "")
{
$die[$i] = rand(1,6);
}
else
{
$die[$i] = $keepIt[$i];
} // end if/else

$theFile = "die" . $die[$i] . ".jpg";

//print out images
print <<<HERE
<td>
image

HERE;

//print out a check box on the first roll only
if($secondRoll == false)
{
print <<<HERE
<input type = "checkbox"
name = "keepIt[$i]"
value = $die[$i]>

HERE;
} // end if

//print out submit button and end of table
print





HERE;

function evaluate()
{
global $die, $cash;

//set up payoff
$payoff = 0;

//subtract some money for this roll
$cash -= 2;

//count the dice
$numVals = array(6);

for($theVal = 1; $theVal <= 6; $theVal++)
{
for($dieNum = 0; $dieNum < 5; $dieNum++)
{
if($die[$dieNum] == $theVal)
{
$numVals[$theVal]++;
} // end if
} // end for loop
} // end for loop

//print out results
// for($i = 1; $i <= 6; $i++)
// {
// print "$i: $numVals[$i]<br>
";
// } // end for loop

// count how many pairs, threes, fours, fives
$numPairs = 0;
$numThrees = 0;
$numFours = 0;
$numFives = 0;

for($i = 1; $i <= 6; $i++)
{
switch($numVals[$i])
{
case: 2
$numPairs++;
break;
case: 3
$numThrees++;
break;
case: 4
$numFours++;
break;
case: 5
$numFives++;
break;
} // end switch
} // end for loop

// Check for two pairs
if($numPairs == 2)
{
print "You have two pairs!<br>
";
$payoff = 1;
} // end of

// check for three of a kind and full house
if($numThrees == 1)
{
if($numPairs == 1)
{
//Three of a kind and a pair is a full house
print "You have a full house!

";
$payoff = 5;
}
else
{
print "You have three of a kind!



";
$payoff = 2;
} // end 'pair' if
} // end 'three'if

//check for four of a kind
if($numFours == 1)
{
print "You have four of a kind!

";
$payoff = 5;
} // end if

// check for five of a kind
if($numVals == 1)
{
print "You got five of a kind!

";
$payoff = 10;
} // end if

// check for flushes
if(($numVals[1] == 1)
&&($numVals[2] == 1)
&&($numVals[3] == 1)
&&($numVals[4] == 1)
&&($numVals[5] == 1))
{
print "You have a flush!

";
$payoff = 10;
} // end if

if(($numVals[2] == 1)
&&($numVals[3] == 1)
&&($numVals[4] == 1)
&&($numVals[5] == 1)
&&($numVals[6] == 1))
{
print "You have a flush!

";
$payoff = 10;
} // end if

print "You bet 2

";
print "payoff is $payoff

";
$cash += $payoff;
} // END FUNCTIOn evaluate

?>

[/code]

Sign In or Register to comment.