So I have managed to get this far with the code. I’m making a simple tic tac toe game for my school project and I would be very happy if someone could help me with my code.
[code=php]
<!DOCTYPE html>
<?php
$WINNER = ‘N’;
$box = array(”, ”, ”, ”, ”, ”, ”, ”, ”);
if (isset($_POST[“sb”])) {
$box[0] = $_POST[“box0”];
$box[1] = $_POST[“box1”];
$box[2] = $_POST[“box2”];
$box[3] = $_POST[“box3”];
$box[4] = $_POST[“box4”];
$box[5] = $_POST[“box5”];
$box[6] = $_POST[“box6”];
$box[7] = $_POST[“box7”];
$box[8] = $_POST[“box8”];
if (($box[0] == ‘x’ && $box[1] == ‘x’ && $box[2] == ‘x’) ||
($box[3] == ‘x’ && $box[4] == ‘x’ && $box[5] == ‘x’) ||
($box[6] == ‘x’ && $box[7] == ‘x’ && $box[8] == ‘x’) ||
($box[0] == ‘x’ && $box[3] == ‘x’ && $box[6] == ‘x’) ||
($box[1] == ‘x’ && $box[4] == ‘x’ && $box[7] == ‘x’) ||
($box[2] == ‘x’ && $box[5] == ‘x’ && $box[8] == ‘x’) ||
($box[0] == ‘x’ && $box[4] == ‘x’ && $box[8] == ‘x’) ||
($box[2] == ‘x’ && $box[4] == ‘x’ && $box[6] == ‘x’)) {
$WINNER = ‘x’;
echo ‘WINNER IS: X’;
}
$blanck = 0;
for ($i = 0; $i <= 8; $i++) {
if ($box[$i] == ”) {
$blanck = 1;
}
}
if ($blanck == 1 && $WINNER == ‘n’) {
$i = rand() % 8;
while ($box[$i] != ”) {
$i = rand() % 8;
}
$box[$i] = ‘o’;
if (($box[0] == ‘o’ && $box[1] == ‘o’ && $box[2] == ‘o’) ||
($box[3] == ‘o’ && $box[4] == ‘o’ && $box[5] == ‘o’) ||
($box[6] == ‘o’ && $box[7] == ‘o’ && $box[8] == ‘o’) ||
($box[0] == ‘o’ && $box[3] == ‘o’ && $box[6] == ‘o’) ||
($box[1] == ‘o’ && $box[4] == ‘o’ && $box[7] == ‘o’) ||
($box[2] == ‘o’ && $box[5] == ‘o’ && $box[8] == ‘o’) ||
($box[0] == ‘o’ && $box[4] == ‘o’ && $box[8] == ‘o’) ||
($box[2] == ‘o’ && $box[4] == ‘o’ && $box[6] == ‘o’)) {
$WINNER = ‘o’;
echo ‘WINNER IS: O’;
}
} else {
$WINNER =’t’;
print ‘Tied game’;
}
}
?>
<html>
<head>
<meta charset=”UTF-8″>
<title></title>
</head>
<body>
<form name=”tictactoe” action=”index.php” method=”POST”>
<?php
for ($i = 0; $i <= 8; $i++) {
printf(‘<input type=”text” name=”box%s” value=”%s” />’, $i, $box[$i]);
if ($i == 2 || $i == 5 || $i == 8) {
echo ‘</br>’;
}
}
if ($WINNER == ‘n’) {
printf(‘<input type = “submit” value = “GO” name = “sb” />’);
} else {
printf(‘<input type=”reset” value=”Play again” name=”newGame” onclick=”window.location.href=’index.php'” />’);
}
?>
</form>
</body>
</html>