od pc manik » úte bře 24, 2009 17:34
<?php
if ($game==0)
{
//Initialize
$a=0; $b=0; $c=0;
$d=0; $e=0; $f=0;
$g=0; $h=0; $i=0;
$player=1;
}
else
{
//Advance to next player
$player = (++$player > 2) ? 1 : 2;
}
$pieces = array ( $a,$b,$c,$d,$e,$f,$g,$h,$i );
?>
<?php
function draw_piece($idx,$p,$player)
{
switch ($p[$idx])
{
case 0: //Blank
$p[$idx]=$player;
$url = "<a href=\"piskvorky.php?game=1&";
$url .= "a=$p[0]&b=$p[1]&c=$p[2]&";
$url .= "d=$p[3]&e=$p[4]&f=$p[5]&";
$url .= "g=$p[6]&h=$p[7]&i=$p[8]&";
$url .= "player=$player";
$url .= "\">";
$url .= "<img src=\"blank.gif\" width=64 height=64 border=0></a>";
print $url;
break;
case 1: //Red-O
print "<img src=\"ro.gif\" border=0>";
break;
case 2: //Blue-X
print "<img src=\"bx.gif\" border=0>";
break;
default:
print "<img src=\"blank.gif\" border=0>";
break;
}
}
?>
<html>
<body bgcolor="#000000">
<font color="#00FF00">
<center><h1>PHP Tic-Tac-Toe</h1></center>
</font>
<table align=center cellpadding=0 cellspacing=0 border=0>
<tr>
<td>
<? draw_piece(0,$pieces,$player) ?>
</td>
<td><img src="pix.gif" width=10 height=64></td>
<td>
<? draw_piece(1,$pieces,$player) ?>
</td>
<td><img src="pix.gif" width=10 height=64></td>
<td>
<? draw_piece(2,$pieces,$player) ?>
</td>
</tr>
<tr bgcolor=blue height=10></tr>
<tr>
<td><img src="pix.gif" width=64 height=10></td>
<td><img src="pix.gif" width=10 height=10></td>
<td><img src="pix.gif" width=64 height=10></td>
<td><img src="pix.gif" width=10 height=10></td>
<td><img src="pix.gif" width=64 height=10></td>
</tr>
<tr>
<td>
<? draw_piece(3,$pieces,$player) ?>
</td>
<td><img src="pix.gif" width=10 height=64></td>
<td>
<? draw_piece(4,$pieces,$player) ?>
</td>
<td><img src="pix.gif" width=10 height=64></td>
<td>
<? draw_piece(5,$pieces,$player) ?>
</td>
</tr>
<tr>
<td><img src="pix.gif" width=64 height=10></td>
<td><img src="pix.gif" width=10 height=10></td>
<td><img src="pix.gif" width=64 height=10></td>
<td><img src="pix.gif" width=10 height=10></td>
<td><img src="pix.gif" width=64 height=10></td>
</tr>
<tr>
<td>
<? draw_piece(6,$pieces,$player) ?>
</td>
<td><img src="pix.gif" width=10 height=64></td>
<td>
<? draw_piece(7,$pieces,$player) ?>
</td>
<td><img src="pix.gif" width=10 height=64></td>
<td>
<? draw_piece(8,$pieces,$player) ?>
</td>
</tr>
</table>
<FORM ACTION='piskvorky.php?game=0' METHOD=POST>
<center>
<Input Type=submit Value='Nová hra'>
</center>
</body>
</html>
<?php
if ($game==0)
{
//Initialize
$a=0; $b=0; $c=0;
$d=0; $e=0; $f=0;
$g=0; $h=0; $i=0;
$player=1;
}
else
{
//Advance to next player
$player = (++$player > 2) ? 1 : 2;
}
$pieces = array ( $a,$b,$c,$d,$e,$f,$g,$h,$i );
?>
<?php
function draw_piece($idx,$p,$player)
{
switch ($p[$idx])
{
case 0: //Blank
$p[$idx]=$player;
$url = "<a href=\"piskvorky.php?game=1&";
$url .= "a=$p[0]&b=$p[1]&c=$p[2]&";
$url .= "d=$p[3]&e=$p[4]&f=$p[5]&";
$url .= "g=$p[6]&h=$p[7]&i=$p[8]&";
$url .= "player=$player";
$url .= "\">";
$url .= "<img src=\"blank.gif\" width=64 height=64 border=0></a>";
print $url;
break;
case 1: //Red-O
print "<img src=\"ro.gif\" border=0>";
break;
case 2: //Blue-X
print "<img src=\"bx.gif\" border=0>";
break;
default:
print "<img src=\"blank.gif\" border=0>";
break;
}
}
?>
<html>
<body bgcolor="#000000">
<font color="#00FF00">
<center><h1>PHP Tic-Tac-Toe</h1></center>
</font>
<table align=center cellpadding=0 cellspacing=0 border=0>
<tr>
<td>
<? draw_piece(0,$pieces,$player) ?>
</td>
<td><img src="pix.gif" width=10 height=64></td>
<td>
<? draw_piece(1,$pieces,$player) ?>
</td>
<td><img src="pix.gif" width=10 height=64></td>
<td>
<? draw_piece(2,$pieces,$player) ?>
</td>
</tr>
<tr bgcolor=blue height=10></tr>
<tr>
<td><img src="pix.gif" width=64 height=10></td>
<td><img src="pix.gif" width=10 height=10></td>
<td><img src="pix.gif" width=64 height=10></td>
<td><img src="pix.gif" width=10 height=10></td>
<td><img src="pix.gif" width=64 height=10></td>
</tr>
<tr>
<td>
<? draw_piece(3,$pieces,$player) ?>
</td>
<td><img src="pix.gif" width=10 height=64></td>
<td>
<? draw_piece(4,$pieces,$player) ?>
</td>
<td><img src="pix.gif" width=10 height=64></td>
<td>
<? draw_piece(5,$pieces,$player) ?>
</td>
</tr>
<tr>
<td><img src="pix.gif" width=64 height=10></td>
<td><img src="pix.gif" width=10 height=10></td>
<td><img src="pix.gif" width=64 height=10></td>
<td><img src="pix.gif" width=10 height=10></td>
<td><img src="pix.gif" width=64 height=10></td>
</tr>
<tr>
<td>
<? draw_piece(6,$pieces,$player) ?>
</td>
<td><img src="pix.gif" width=10 height=64></td>
<td>
<? draw_piece(7,$pieces,$player) ?>
</td>
<td><img src="pix.gif" width=10 height=64></td>
<td>
<? draw_piece(8,$pieces,$player) ?>
</td>
</tr>
</table>
<FORM ACTION='piskvorky.php?game=0' METHOD=POST>
<center>
<Input Type=submit Value='Nová hra'>
</center>
</body>
</html>