NIM

Einfache Version des Streichholzspiels.

Sourcecode von NIM:

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="nim.php">
<table width="250" align="center" bordercolor="#000000">
<tr bgcolor="#000000">
<td height="50" colspan="2" bgcolor="#000000"><div align="center" class="Stil1">NIM</div></td>
</tr>
<tr>
<td height="50" colspan="2" bgcolor="#000000"><div align="center"><em><span class="Stil4">Ziehe 1,
2 oder 3<br>
Der Letzte verliert
</span></em></div></td>
</tr>
<tr>
<td width="50%" height="50" bgcolor="#000000">
<div align="right" class="Stil4">Anzahl:</div> </td>
<td width="50%" height="50" bgcolor="#000000">
<div align="center" class="Stil4">

<div align="center">
<?php
$player=1;
if(isset($_POST['btn_ok']))
{
$hoe=$_POST['hoelzer'];
$player=$_POST['player'];
}
else
{
$hoe=rand(5,20);
}
if(isset($_POST['reset']))
{
$hoe=rand(5,20);
$player=1;
}
if(isset($_POST['txt_wahl']))
{
$wahl=$_POST['txt_wahl'];
if($wahl>0&&$wahl<4)
{
$hoe-=$wahl;
$player=1+$player%2;

}
}

echo "<input type=\"hidden\" name=\"player\" value=\"$player\">\n";
echo "<input type=\"hidden\" name=\"hoelzer\" value=\"$hoe\">\n";
if($hoe<2)
{
echo "Spieler $player verliert!";
}
else
{
echo "$hoe";
}
?>
</div>
</div> </td>
</tr>
<tr>
<td width="50%" height="50" bgcolor="#000000">
<div align="right" class="Stil4">Am Zug ist <?php echo $player;?></div> </td>
<td width="50%" height="50" bgcolor="#000000">
<div align="center" class="Stil4">

<div align="center">
<input name="txt_wahl" type="text" size="10" maxlength="1">
</div>
</div> </td>
</tr>
<tr>
<td width="50%" height="50" bgcolor="#000000">
<div align="right"><span class="Stil5"></span></div> </td>
<td width="50%" height="50" bgcolor="#000000">
<div align="center" class="Stil4">
<input name="btn_ok" type="submit" id="btn_ok" value="OK">
<input name="reset" type="submit" id="reset" value="Reset">
</div> </td>
</tr>
</table>
</form>
</body>

<<zurück>>