Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Debuging php poker program

Garrett85Garrett85 Posts: 168Member
When I first started this program it worked fine in the browser, but now I'M getting a blank page.

[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

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

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

// 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 four

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

// 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;
}

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

";
$payoff = 10;
}

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

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

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

";
$payoff = 10;
}

function printStuff()
{
global $cash, $secondRoll;

print "Cash: $cash
";

// store variables in hidden fields
print <<<HERE

<input type = "hidden"
name = "secondRoll"
value = "$secondRoll">


HERE;
} // end printStuff

?>



[/code]
Sign In or Register to comment.