Dice + Keeping State
Posted: Sat Mar 07, 2009 1:54 pm
So I'm a .php novice. I'm making this dice game and it involves keeping state.
I have it right now so you see an image of 5 dice, they have 5 radio buttons beneath them, and if you hit the roll button it randomizes the dice.
That was easy.
However, I can't seem to keep state for the life of me. ._.; I was wondering if anyone could help me? I'm just trying to get it to where if someone checks a radio box, the dice in that "slot" does not change. I just can't figure out the logic. lakdjf;ajd;fa;. I'm about to pull my hair out, been working on it for 4 hours.
This is what I have so far;
Any help would be appreciated.
I have it right now so you see an image of 5 dice, they have 5 radio buttons beneath them, and if you hit the roll button it randomizes the dice.
That was easy.
However, I can't seem to keep state for the life of me. ._.; I was wondering if anyone could help me? I'm just trying to get it to where if someone checks a radio box, the dice in that "slot" does not change. I just can't figure out the logic. lakdjf;ajd;fa;. I'm about to pull my hair out, been working on it for 4 hours.
This is what I have so far;
Code: Select all
<? session_start(); ?>
<html>
<head>
<title>Yahtzee! Or something kind of like it...</title>
</head>
<body>
<center>
<?
$d1 = mt_rand(1,6);
$d2 = mt_rand(1,6);
$d3 = mt_rand(1,6);
$d4 = mt_rand(1,6);
$d5 = mt_rand(1,6);
lock1 = 0;
lock2 = 0;
lock3 = 0;
lock4 = 0;
lock5 = 0;
for ($i = 1; $i <= 5; $i++)
{
$roll = mt_rand(1,6);
echo "<img src='dice{$roll}.gif' alt='$roll' /> ";
if ($roll == 1)
{
$_SESSION['one'] = $_SESSION['one'] + 1;
}
else if ($roll == 2)
{
$_SESSION['two'] = $_SESSION['two'] + 1;
}
else if ($roll == 3)
{
$_SESSION['three'] = $_SESSION['three'] + 1;
}
else if ($roll == 4)
{
$_SESSION['four'] = $_SESSION['four'] + 1;
}
else if ($roll == 5)
{
$_SESSION['five'] = $_SESSION['five'] + 1;
}
else if ($roll == 6)
{
$_SESSION['six'] = $_SESSION['six'] +1;
}
}
?>
<?
?>
<form>
<table border="0" cellpadding="13.5">
<td><input type="checkbox" name="lock1" id="lock1" value"<?$d1?>/></td>
<td><input type="checkbox" name="lock2" id="lock2" value"<?$d2?>/></td>
<td><input type="checkbox" name="lock3" id="lock3" value"<?$d3?>/></td>
<td><input type="checkbox" name="lock4" id="lock4" value"<?$d4?>/></td>
<td><input type="checkbox" name="lock5" id="lock5" value"<?$d5?>/></td>
</table>
<p><input type="submit" value="Roll dice!" />
</center>
</form>
</body>
</html>