IsolatedEarthling
January 16th, 2009, 01:59 PM
I am supposed to do a snake-eye thingy on PHP. The program chooses 2 random numbers as dice rolls, and if the dice rolls are different, the player gets points equal to the sum of the dice rolls. It continues until the player gets two identical rolls, in this case the game ends, with the player getting the score before the identical rolls as the final score. The problem is, whenever the player presses the button to generate the dice rolls, the page refreshes, resulting in the total score being wiped clean, i.e. back to 0. Please help. Thnx
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Snake-Eyes Game</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="submit" name="btnRoll" id="btnRoll" value="Roll Dice" />
</label>
<a href="index.html">Return to Homepage</a>
</form>
<?php
$dice1=rand(1,6);
$dice2=rand(1,6);
echo "\n".'Dice 1: '.$dice1;
echo "\n".'Dice 2: '.$dice2;
if($dice1 != $dice2)
{$score2 = $score1+$dice1+$dice2;
echo "\n".'Score: '. $score2;
$score1 = $score2;}
else
{echo "\n".'Game Over!';}
?>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Snake-Eyes Game</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="submit" name="btnRoll" id="btnRoll" value="Roll Dice" />
</label>
<a href="index.html">Return to Homepage</a>
</form>
<?php
$dice1=rand(1,6);
$dice2=rand(1,6);
echo "\n".'Dice 1: '.$dice1;
echo "\n".'Dice 2: '.$dice2;
if($dice1 != $dice2)
{$score2 = $score1+$dice1+$dice2;
echo "\n".'Score: '. $score2;
$score1 = $score2;}
else
{echo "\n".'Game Over!';}
?>
</body>
</html>