-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
223 lines (192 loc) · 7.47 KB
/
index.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
// dungeon crawler sample by Andreas Ganje (https://ganje.de)
// legend:
// w - wall
// p - passage
$level = [
['w', 'w', 'w', 'w', 'w', 'w'],
['w', 'p', 'p', 'p', 'w', 'w'],
['w', 'p', 'w', 'p', 'w', 'w'],
['w', 'p', 'p', 'p', 'p', 'w'],
['w', 'p', 'w', 'p', 'w', 'w'],
['w', 'p', 'w', 'p', 'w', 'w'],
['w', 'w', 'w', 'w', 'w', 'w'],
];
$x = isset($_GET['x']) ? $_GET['x'] : 2;
$y = isset($_GET['y']) ? $_GET['y'] : 2;
$d = isset($_GET['d']) ? $_GET['d'] : 's';
// -1 because of array index starting from 0
$xToCheck = $x - 1;
$yToCheck = $y - 1;
// automap
function renderMap($level, $x, $y, $d)
{
// direction image for players position
if ($d == 'n') {
$char = '△';
} elseif ($d == 'e') {
$char = '▷';
} elseif ($d == 's') {
$char = '▽';
} elseif ($d == 'w') {
$char = '◁';
} else {
$char = 'X';
}
// map as table
$map = '<table>';
// do horizontal
foreach ($level as $keyY => $valY) {
$map .= '<tr>';
// do vertical
foreach ($valY as $keyX => $valX) {
$map .= '<td>';
// draw walls
if ($valX === 'w') {
$map .= '⬛';
}
// draw char
if ($keyY == $y - 1 && $keyX == $x - 1) {
$map .= '<span style="font-size: 1em;">' . $char . '</span>';
}
$map .= '</td>';
}
$map .= '</tr>';
}
$map .= '</table>';
return $map;
}
// control arrows
$labelFront = '▲';
$labelBack = '▼';
$labelLeft = '◤';
$labelLeft2 = '◀';
$labelRight = '◥';
$labelRight2 = '▶';
// moving directions - create link for each direction, if possible
if ($d == 'n') {
$l = '<a href="index.php?x=' . $x . '&y=' . $y . '&d=w" style="text-decoration: none;">' . $labelLeft . '</a>';
$r = '<a href="index.php?x=' . $x . '&y=' . $y . '&d=e" style="text-decoration: none;">' . $labelRight . '</a>';
if (@$level[$yToCheck - 1][$xToCheck] == 'p') {
$f = '<a href="index.php?x=' . $x . '&y=' . ($y - 1) . '&d=' . $d . '" style="text-decoration: none;">' . $labelFront . '</a>';
} else {
$f = $labelFront;
}
if (@$level[$yToCheck][$xToCheck + 1] == 'p') {
$rr = '<a href="index.php?x=' . ($x + 1) . '&y=' . $y . '&d=' . $d . '" style="text-decoration: none;">' . $labelRight2 . '</a>';
} else {
$rr = $labelRight2;
}
if (@$level[$yToCheck][$xToCheck - 1] == 'p') {
$ll = '<a href="index.php?x=' . ($x - 1) . '&y=' . $y . '&d=' . $d . '" style="text-decoration: none;">' . $labelLeft2 . '</a>';
} else {
$ll = $labelLeft2;
}
if (@$level[$yToCheck + 1][$xToCheck] == 'p') {
$b = '<a href="index.php?x=' . $x . '&y=' . ($y + 1) . '&d=' . $d . '" style="text-decoration: none;">' . $labelBack . '</a>';
} else {
$b = $labelBack;
}
} elseif ($d == 'e') {
$l = '<a href="index.php?x=' . $x . '&y=' . $y . '&d=n" style="text-decoration: none;">' . $labelLeft . '</a>';
$r = '<a href="index.php?x=' . $x . '&y=' . $y . '&d=s" style="text-decoration: none;">' . $labelRight . '</a>';
if (@$level[$yToCheck][$xToCheck + 1] == 'p') {
$f = '<a href="index.php?x=' . ($x + 1) . '&y=' . $y . '&d=' . $d . '" style="text-decoration: none;">' . $labelFront . '</a>';
} else {
$f = $labelFront;
}
if (@$level[$yToCheck + 1][$xToCheck] == 'p') {
$rr = '<a href="index.php?x=' . $x . '&y=' . ($y + 1) . '&d=' . $d . '" style="text-decoration: none;">' . $labelRight2 . '</a>';
} else {
$rr = $labelRight2;
}
if (@$level[$yToCheck - 1][$xToCheck] == 'p') {
$ll = '<a href="index.php?x=' . $x . '&y=' . ($y - 1) . '&d=' . $d . '" style="text-decoration: none;">' . $labelLeft2 . '</a>';
} else {
$ll = $labelLeft2;
}
if (@$level[$yToCheck][$xToCheck - 1] == 'p') {
$b = '<a href="index.php?x=' . ($x - 1) . '&y=' . $y . '&d=' . $d . '" style="text-decoration: none;">' . $labelBack . '</a>';
} else {
$b = $labelBack;
}
} elseif ($d == 's') {
$l = '<a href="index.php?x=' . $x . '&y=' . $y . '&d=e" style="text-decoration: none;">' . $labelLeft . '</a>';
$r = '<a href="index.php?x=' . $x . '&y=' . $y . '&d=w" style="text-decoration: none;">' . $labelRight . '</a>';
if (@$level[$yToCheck + 1][$xToCheck] == 'p') {
$f = '<a href="index.php?x=' . $x . '&y=' . ($y + 1) . '&d=' . $d . '" style="text-decoration: none;">' . $labelFront . '</a>';
} else {
$f = $labelFront;
}
if (@$level[$yToCheck][$xToCheck - 1] == 'p') {
$rr = '<a href="index.php?x=' . ($x - 1) . '&y=' . $y . '&d=' . $d . '" style="text-decoration: none;">' . $labelRight2 . '</a>';
} else {
$rr = $labelRight2;
}
if (@$level[$yToCheck][$xToCheck + 1] == 'p') {
$ll = '<a href="index.php?x=' . ($x + 1) . '&y=' . $y . '&d=' . $d . '" style="text-decoration: none;">' . $labelLeft2 . '</a>';
} else {
$ll = $labelLeft2;
}
if (@$level[$yToCheck - 1][$xToCheck] == 'p') {
$b = '<a href="index.php?x=' . $x . '&y=' . ($y - 1) . '&d=' . $d . '" style="text-decoration: none;">' . $labelBack . '</a>';
} else {
$b = $labelBack;
}
} elseif ($d == 'w') {
$l = '<a href="index.php?x=' . $x . '&y=' . $y . '&d=s" style="text-decoration: none;">' . $labelLeft . '</a>';
$r = '<a href="index.php?x=' . $x . '&y=' . $y . '&d=n" style="text-decoration: none;">' . $labelRight . '</a>';
if (@$level[$yToCheck][$xToCheck - 1] == 'p') {
$f = '<a href="index.php?x=' . ($x - 1) . '&y=' . $y . '&d=' . $d . '" style="text-decoration: none;">' . $labelFront . '</a>';
} else {
$f = $labelFront;
}
if (@$level[$yToCheck - 1][$xToCheck] == 'p') {
$rr = '<a href="index.php?x=' . $x . '&y=' . ($y - 1) . '&d=' . $d . '" style="text-decoration: none;">' . $labelRight2 . '</a>';
} else {
$rr = $labelRight2;
}
if (@$level[$yToCheck + 1][$xToCheck] == 'p') {
$ll = '<a href="index.php?x=' . $x . '&y=' . ($y + 1) . '&d=' . $d . '" style="text-decoration: none;">' . $labelLeft2 . '</a>';
} else {
$ll = $labelLeft2;
}
if (@$level[$yToCheck][$xToCheck + 1] == 'p') {
$b = '<a href="index.php?x=' . ($x + 1) . '&y=' . $y . '&d=' . $d . '" style="text-decoration: none;">' . $labelBack . '</a>';
} else {
$b = $labelBack;
}
}
// render user interface
?>
<!DOCTYPE html>
<html lang="de">
<head>
<title>dungeon crawler</title>
<meta charset="utf-8"/>
</head>
<body>
<?php
echo '<div>' . strtoupper($d) . ' (x' . $x . ', ' . 'y' . $y . ')</div>'
. '<p></p>'
. '<div>' . renderMap($level, $x, $y, $d) . '</div>'
. '<p></p>'
. '<div><table>'
. '<tr>'
. '<td><span style="font-size: 2em;">' . $l . '</span></td><td>'
. '<span style="font-size: 2em;">' . $f . '</span></td><td>'
. '<span style="font-size: 2em;">' . $r . '</span></td>'
. '</tr>'
. '<tr>'
. '<td><span style="font-size: 2em;">' . $ll . '</span></td>'
. '<td><span style="font-size: 2em;">' . $b . '</span></td>'
. '<td><span style="font-size: 2em;">' . $rr . '</span></td>'
. '</tr>'
. '</table></div>'
. '<p></p>'
. '<div style="width: 350px; height: 350px; background-color: black;">'
. '<img style="width: 350px; height: 350px; border: 1px solid rgb(0, 0, 0);" src="./dungeon.php?x=' . $x . '&y=' . $y . '&d=' . $d . '"/>'
. '</div>';
?>
</body>
</html>