Poker Dice

Second Roll\n"; $secondRoll = FALSE; evaluate(); } else { print "

First Roll

\n"; $secondRoll = TRUE; } //end if printStuff(); //function to roll the dice and to select which to keep function rollDice(){ global $die, $secondRoll, $keepIt; print "\n\n"; for ($i = 0; $i < 5; $i++){ //rolling 5 dice if ($keepIt[$i] == ""){ //if that dice in the array hasn't been set to be kept $die[$i] = rand(1,6); //pick a random die for the same die in the 'die' array } else { $die[$i] = $keepIt[$i]; // if it has been kept then set the die to the same value as the keep it value } // end if $theFile = "images/die".$die[$i].".jpg"; //create the file path for the die image //print out dice images print <<
HERE; //print out a checkbox on first roll only if ($secondRoll == FALSE){ print << HERE; } //end if print "\n"; } // end for loop //print out submit button and end of table print <<
HERE; } //end rollDice //evaluate function to examine $die array and see ifuser has achieved reward based on the results function evaluate(){ global $die, $cash; //set up payoff; $payoff = 0; //subtract some money for this roll $cash -= 2; //count the dice $numVals = array(6); //numVals holds the dice counting data for ($theVal = 1; $theVal <= 6; $theVal++){ //for each of the number of spots on the die for ($dieNum = 0; $dieNum < 5; $dieNum++){ //for each of the 5 dice if($die[$dieNum] == $theVal){ //if the value of the dice matches the number of spots $numVals[$theVal]++; //add one to the number of spots } //end if } //end 'dieNum' for loop } // end 'theVal' for loop //print out results DEBUGGING CODE // for ($i = 1; $i <= 6; $i++){ // print "$i: $numVals[$i]
\n"; // } //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 "Your have two pairs!
\n"; $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!
\n"; $payoff = 5; } else { print "You have three of a kind!
\n"; $payoff = 2; } //end 'pair' if } //end 'three' if //check for four of a kind if ($numFours == 1){ print "You have four of a kind!
\n"; $payoff = 5; } //end if //check for five of a kind if ($numFives == 1){ print "You got Five of a kind!
\n"; $payoff = 10; } //end if //check for flushes if (($numVals[1] == 1) //if number of dice with one spot equals 1 && ($numVals[2] == 1) //and number of dice with two spots equals 1 && ($numVals[3] == 1) //and number of dice with three spots equals 1 && ($numVals[4] == 1) //and number of dice with four spots equals 1 && ($numVals[5] == 1)){ //and number of dice with five spots equals 1 print "You have a flush!
\n"; $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!
\n"; $payoff = 10; } // end if print "You bet 2
\n"; print "Payout is $payoff
\n"; $cash += $payoff; } //end evaluate function printStuff(){ global $cash, $secondRoll; print "Cash: $cash\n"; //store variables in hidden fields print << HERE; } //end printStuff ?>