forked from kokonior/PHP-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dicky.php
84 lines (63 loc) · 1.86 KB
/
Dicky.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
require_once "templates/header.php";
if (! playersRegistered()) {
header("location: index.php");
}
if ($_POST['cell']) {
$win = play($_POST['cell']);
if ($win) {
header("location: result.php?player=" . getTurn());
}
}
if (playsCount() >= 9) {
header("location: result.php");
}
?>
<h2><?php echo currentPlayer() ?>'s turn</h2>
<form method="post" action="play.php">
<table class="tic-tac-toe" cellpadding="0" cellspacing="0">
<tbody>
<?php
$lastRow = 0;
for ($i = 1; $i <= 9; $i++) {
$row = ceil($i / 3);
if ($row !== $lastRow) {
$lastRow = $row;
if ($i > 1) {
echo "</tr>";
}
echo "<tr class='row-{$row}'>";
}
$additionalClass = '';
if ($i == 2 || $i == 8) {
$additionalClass = 'vertical-border';
}
else if ($i == 4 || $i == 6) {
$additionalClass = 'horizontal-border';
}
else if ($i == 5) {
$additionalClass = 'center-border';
}
?>
<td class="cell-<?= $i ?> <?= $additionalClass ?>">
<?php if (getCell($i) === 'x'): ?>
X
<?php elseif (getCell($i) === 'o'): ?>
O
<?php else: ?>
<input type="radio" name="cell" value="<?= $i ?>" onclick="enableButton()"/>
<?php endif; ?>
</td>
<?php } ?>
</tr>
</tbody>
</table>
<button type="submit" disabled id="play-btn">Play</button>
</form>
<script type="text/javascript">
function enableButton() {
document.getElementById('play-btn').disabled = false;
}
</script>
<?php
require_once "templates/footer.php";