:)
我试图让游戏变得有趣,但我遇到了一个问题。
嗯,当你打开游戏时,它会显示一个RAND号码。 rand(1,20)..(Min = 1 Max = 20)..你有2个按钮(较小)(较大)
它有2个随机函数..
所以,你必须猜测下一个数字是高于还是低于默认值。
但有一个问题。程序不能正确比较两个随机函数。 :(
<?php
session_start();
?>
<div id="pogodak">
<?php
$rand = rand(1,20);
$rand2 = rand(1,20);
if(isset($_POST['smaller']))
{
if($rand2<=$rand)
{
echo "<font color=#0f0>Succeed</font>";
$_SESSION['hit']=$_SESSION['hit']+1;
}
else
{
echo "<font color=#DE001A>Fail</font>";
unset($_SESSION['hit']);
session_destroy;
}
}
if(isset($_POST['bigger']))
{
if($rand2>=$rand)
{
echo "<font color=#0f0>Succeed</font>";
$_SESSION['hit']=$_SESSION['hit']+1;
}
else
{
echo "<font color=#DE001A>fail</font>";
unset($_SESSION['hit']);
session_destroy;
}
}
session_destroy;
?>
</div>
那里......
<table width="1000">
<form action="" method="post">
<tr>
<td width="321" align="center" valign="middle">
<input type="submit" name="smaller" value="Smaller" class="button"/></td>
<td width="348" align="center" valign="middle" class="veliko"><? echo $rand;?></td>
<td width="315" align="center" valign="middle" class="veliko">
<input type="submit" name="bigger" value="Bigger" class="button"/></td>
</tr>
<tr>
<td height="83" colspan="3" align="center" valign="middle" class="srednje"><? echo "Hits: " . $_SESSION['hits']"</br>";?></td>
</tr>
<tr>
<td height="83" align="center" valign="middle" >Nickname:</td>
<td height="83" align="center" valign="middle" ><input type="text" name="name"/></td>
<td height="83" align="center" valign="middle" ><input type="submit" name="kraj" value="Finish!" />
</td>
</tr>
</form>
</table>
答案 0 :(得分:0)
$ rand和$ rand2获得相同的值,尝试在2个值之间放置另一个种子,并在数字具有相同值时检查回调
$rand = rand(1,20);
//srand goes here
$rand2 = rand(1,20);