-
Notifications
You must be signed in to change notification settings - Fork 0
/
index2.php
73 lines (58 loc) · 1.31 KB
/
index2.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
<?php
require_once('vendor/autoload.php');
use App\Game;
use App\Ship;
use App\GameSession;
session_start();
$game = new Game;
$game->start();
$input = $game->listenForInput();
if($game->isFinished()) {
session_destroy();
echo "Well done! You completed the game in ". GameSession::getAction() . "shots.";
echo "<br /><a href='/index.php'>Try again</a>";
return;
}
if ($input === false) {
echo "<pre>\n *** ERROR *** \n</pre>";
}
if ($game->actionResult && strlen($game->actionResult)) {
echo "<pre>\n $game->actionResult \n</pre>";
}
?>
<html>
<pre>
<?= $game->playergrid->renderColumns(); ?>
<?= $game->renderGrid(); ?>
</pre>
<p>
<form name="input" action="index.php" method="post">
Enter coordinates (row, col), e.g. A5
<input type="input" size="5" name="coord" autocomplete="off" autofocus="">
<input type="submit">
</form>
</p>
<pre>
<?php
$i = 1;
foreach(GameSession::getItem('ships_coordinates') as $point => $ship) {
echo "\n $i $point";
$i++;
}
?>
</pre>
<pre>
<?php
$i = 1;
foreach(GameSession::getItem('ships') as $key => $ship) {
echo "\n $i ". count($ship->coords);
foreach($ship->coords as $key => $pair) {
list($row,$col) = $pair;
echo $row.$col.",";
}
// var_dump($ship->coords);
$i++;
}
?>
</pre>
</html>