我可以使用 PHP 并想了解更多关于它的信息!我现在正在模拟 2 个角色之间的某种战斗。问题是,我只能打 1 轮,所以当我点击“战斗”按钮时,它只能打 1 轮。当我再次单击“战斗”时,我似乎无法找出为什么生命值没有改变。这是代码:
<body>
<?php
$Hitpoints1 = 30;
$Hitpoints2 = 30;
?>
<form name="frmFight" form action="" method="post">
<table width="700" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td align="center">Character 1</td>
<td align="center">Character 2</td>
</tr>
<tr>
<td align="center"><?php
if (isset($_POST['btnFight'])) {
$Damage1 += mt_rand(2,9); }
$Total1 = $Hitpoints1 - $Damage1;
echo $Total1; ?></td>
<td align="center"><?php
if (isset($_POST['btnFight'])) {
$Damage2 += mt_rand(2,9); }
$Total2 = $Hitpoints2 - $Damage2;
echo $Total2; ?></td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"> </td>
</tr>
</table>
<p><input name="btnFight" type="submit" value="Submit" /></p>
</form>
</body>