This repository has been archived by the owner on Jan 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 333
/
index.html
486 lines (445 loc) · 31.3 KB
/
index.html
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<!DOCTYPE HTML>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible', content='IE=edge,chrome=1'>
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>Snake!</title>
<!-- favicon -->
<link rel="shortcut icon" href="img/favicon.ico?v=1">
<!-- libraries -->
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<!-- styling -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container-fluid">
<div class="row print-hidden">
<br>
<div class="col-xs-12 col-md-8 col-md-offset-2" style="-webkit-user-select:none">
<img class="img-responsive pull-left" alt="banner.png" src="img/banner.png" style="max-width:30%">
<img class="img-responsive pull-right" alt="title.png" src="img/title.png" style="max-width:60%">
</div>
</div>
<br>
<div class="row">
<div class="col-md-2 hidden" style="overflow:hidden">
<ul class="nav">
<li><a href="#How-to-Play" style="color:white;text-decoration:none">How to Play</a>
<ul class="nav">
<li><a href="play" style="color:white;text-decoration:none">Play Snake</a></li>
</ul>
</li>
<li><a href="#Contributing" style="color:white;text-decoration:none">Contributing</a></li>
<li><a href="#Cheat" style="color:white;text-decoration:none">Cheat</a>
<ul class="nav">
<li><a href="#Writing" style="color:white;text-decoration:none">Writing a cheat</a></li>
<li><a href="#Loading" style="color:white;text-decoration:none">Loading a cheat</a></li>
<li><a href="#Enabling" style="color:white;text-decoration:none">Enabling a cheat</a></li>
</ul>
</li>
<li><a href="#API" style="color:white;text-decoration:none">API</a>
<ul class="nav">
<li><a href="#Snake" style="color:white;text-decoration:none">Snake</a>
<ul class="nav">
<li><a href="#snake-getHeight" style="color:white;text-decoration:none">Snake.getHeight()</a></li>
<li><a href="#snake-getWidth" style="color:white;text-decoration:none">Snake.getWidth()</a></li>
<li><a href="#snake-getPositions" style="color:white;text-decoration:none">Snake.getPositions()</a></li>
<li><a href="#snake-checkPosition" style="color:white;text-decoration:none">Snake.checkPosition()</a></li>
<li><a href="#snake-getPosition" style="color:white;text-decoration:none">Snake.getPosition()</a></li>
<li><a href="#snake-getTailPosition" style="color:white;text-decoration:none">Snake.getTailPosition()</a></li>
<li><a href="#snake-getFoodPosition" style="color:white;text-decoration:none">Snake.getFoodPosition()</a></li>
<li><a href="#snake-getLength" style="color:white;text-decoration:none">Snake.getLength()</a></li>
<li><a href="#snake-getDirection" style="color:white;text-decoration:none">Snake.getDirection()</a></li>
</ul>
</li>
<li><a href="#Cheat" style="color:white;text-decoration:none">Cheat</a>
<ul class="nav">
<li><a href="#cheat-cheat" style="color:white;text-decoration:none">Cheat.cheat()</a></li>
</ul>
</li>
<li><a href="#Position" style="color:white;text-decoration:none">Position</a>
<ul class="nav">
<li><a href="#position-x" style="color:white;text-decoration:none">Position.x</a></li>
<li><a href="#position-y" style="color:white;text-decoration:none">Position.y</a></li>
</ul>
</li>
<li><a href="#Direction" style="color:white;text-decoration:none">Direction</a>
<ul class="nav">
<li><a href="#direction-x" style="color:white;text-decoration:none">Direction.x</a></li>
<li><a href="#direction-y" style="color:white;text-decoration:none">Direction.y</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#top" style="color:white;text-decoration:none">Back to top</a></li>
</ul>
</div>
<div class="col-xs-12 col-md-8 col-md-offset-2">
<h1 id="How-to-Play">How to play</h1>
<p>
<div class="hidden-mobile">
<table style="margin: 10px 0"><tr>
<td class="arrow-wrapper"><span class="glyphicon glyphicon-arrow-left"></span></td>
<td class="key-label">go left</span></td>
<td class="arrow-wrapper"><span class="glyphicon glyphicon-arrow-up"></span></td>
<td class="key-label">go up</span></td>
<td class="arrow-wrapper"><span class="glyphicon glyphicon-arrow-right"></span></td>
<td class="key-label">go right</td>
<td class="arrow-wrapper"><span class="glyphicon glyphicon-arrow-down"></span></td>
<td class="key-label">go down</td>
<td class="arrow-wrapper" style="padding:0 30px">spacebar</td>
<td class="key-label">pause/play</td>
</tr></table>
</div>
<div class="hidden-desktop">
<table style="margin: 10px 0">
<tr>
<td class="mobile-button">go up/left</td>
<td class="mobile-button">go up/right</td>
</tr>
<tr>
<td class="mobile-button">go down/left</td>
<td class="mobile-button">go down/right</td>
</tr>
</table>
Tap the center of the screen to pause/play<br>
</div>
Collect food to grow long and avoid walls and your own tail!
<h3><em><a href="play">Play snake</a></em></h3>
</p>
<br><br>
<h1 id="Contributing">Contributing</h1>
<p>
Snake is an open source project. Contribute to the
<a href="http://github.com/leviathan747/snake">github repository</a>
by submitting issues and pull requests. Submit cheat algorithms into the <span style="color:red">/play/js/cheat</span>
directory.
</p>
<br><br>
<h1 id="Cheat">Cheat</h1>
<p>
This implementation of Snake! was specifically built to explore the interesting strategy of the game. It is designed to be
easily pluggable with configurable behavior. Cheat plugins can be added and interchanged dynamically at runtime using the
sideloader module. The game provides an API available to the developers to access important information about the game
such as the position of the food or the direction the snake is travelling. What are you waiting for? <span style="color:red">
Go write a snake bot!</span>
</p>
<p>
<h3 id="Writing"><em>Writing a cheat</em></h3>
Custom cheats are written by overriding the <code>Cheat</code> object in JavaScript. See more on the API <a href="#API">here</a>.
<h3 id="Loading"><em>Loading a cheat</em></h3>
Cheats can be loaded using the sideloader module. The sideloader module allows users to upload their own JavaScript files or
load cheat files that already exist in the repository. To open the sideloader, press:
<span>
<span class="hidden-mobile" style="color:red">down, up, down, left, right, down, down</span>
<span class="hidden-desktop"style="color:red">bottom-right, top-left, bottom-right, bottom-left, top-right, bottom-right, bottom-right</span>
</span>
.
<div class="panel naked-panel" style="background:black">
<div class="panel-heading" style="padding-left:0">
<a data-toggle="collapse" href="#sideloader-panel" onclick="start_side_help()">HELP</a>
</div>
<div id="sideloader-panel" class="panel-collapse collapse">
<div class="panel-body">
<table class="hidden-mobile" style="margin: 10px 0">
<tr>
<td></td>
<td id="sideloader-up" class="arrow-wrapper"><span class="glyphicon glyphicon-arrow-up"></span></td>
<td></td>
</tr>
<td id="sideloader-left" class="arrow-wrapper"><span class="glyphicon glyphicon-arrow-left"></span></td>
<td id="sideloader-down" class="arrow-wrapper"><span class="glyphicon glyphicon-arrow-down"></span></td>
<td id="sideloader-right" class="arrow-wrapper"><span class="glyphicon glyphicon-arrow-right"></span></td>
<tr>
</tr>
</table>
<table class="hidden-desktop" style="margin: 10px 0">
<tr>
<td id="sideloader-mobile-up" class="mobile-button">top-left</td>
<td id="sideloader-mobile-right" class="mobile-button">top-right</td>
</tr>
<tr>
<td id="sideloader-mobile-left" class="mobile-button">bottom-left</td>
<td id="sideloader-mobile-down" class="mobile-button">bottom-right</td>
</tr>
</table>
<script>
var sideloader_interval = null;
var start_side_help = function() {
if ($("#sideloader-panel").hasClass("in")) {
clearInterval(sideloader_interval);
sideloader_interval = null;
}
else {
clearInterval(sideloader_interval);
sideloader_interval = null;
var sideloader = ["down","up","down","left","right","down","down","blank","blank"];
var i = 0;
sideloader_interval = setInterval(function() {
$("#sideloader-" + sideloader[i%sideloader.length]).css("background","red");
$("#sideloader-mobile-" + sideloader[i%sideloader.length]).css("background","red");
setTimeout(function(elem) {
elem.css("background","black");
}, 300, $("#sideloader-" + sideloader[i%sideloader.length]));
setTimeout(function(elem) {
elem.css("background","black");
}, 300, $("#sideloader-mobile-" + sideloader[i%sideloader.length]));
i++;
}, 500);
}
}
</script>
</div>
</div>
</div>
<h3 id="Enabling"><em>Enabling a cheat</em></h3>
Once loaded, a cheat can be enabled/disabled by pressing:
<span>
<span class="hidden-mobile" style="color:red">up, left, down, left, right, right, right</span>
<span class="hidden-desktop"style="color:red">top-left, bottom-left, bottom-right, bottom-left, top-right, top-right, top-right</span>
</span>
.
<div class="panel naked-panel" style="background:black">
<div class="panel-heading" style="padding-left:0">
<a data-toggle="collapse" href="#enable-panel" onclick="start_enable_help()">HELP</a>
</div>
<div id="enable-panel" class="panel-collapse collapse">
<div class="panel-body">
<table class="hidden-mobile" style="margin: 10px 0">
<tr>
<td></td>
<td id="enable-up" class="arrow-wrapper"><span class="glyphicon glyphicon-arrow-up"></span></td>
<td></td>
</tr>
<td id="enable-left" class="arrow-wrapper"><span class="glyphicon glyphicon-arrow-left"></span></td>
<td id="enable-down" class="arrow-wrapper"><span class="glyphicon glyphicon-arrow-down"></span></td>
<td id="enable-right" class="arrow-wrapper"><span class="glyphicon glyphicon-arrow-right"></span></td>
<tr>
</tr>
</table>
<table class="hidden-desktop" style="margin: 10px 0">
<tr>
<td id="enable-mobile-up" class="mobile-button">top-left</td>
<td id="enable-mobile-right" class="mobile-button">top-right</td>
</tr>
<tr>
<td id="enable-mobile-left" class="mobile-button">bottom-left</td>
<td id="enable-mobile-down" class="mobile-button">bottom-right</td>
</tr>
</table>
<script>
var enable_interval = null;
var start_enable_help = function() {
if ($("#enable-panel").hasClass("in")) {
clearInterval(enable_interval);
enable_interval = null;
}
else {
clearInterval(enable_interval);
enable_interval = null;
var enable = ["up","left","down","left","right","right","right","blank","blank"];
var i = 0;
enable_interval = setInterval(function() {
$("#enable-" + enable[i%enable.length]).css("background","red");
$("#enable-mobile-" + enable[i%enable.length]).css("background","red");
setTimeout(function(elem) {
elem.css("background","black");
}, 300, $("#enable-" + enable[i%enable.length]));
setTimeout(function(elem) {
elem.css("background","black");
}, 300, $("#enable-mobile-" + enable[i%enable.length]));
i++;
}, 500);
}
}
</script>
</div>
</div>
</div>
</p>
<br><br>
<h1 id="API">API</h1>
<p>
This API outlines the documentation of the <a href="#Snake"><em>Snake</em></a> and
<a href="#Cheat"><em>Cheat</em></a> classes as well as the <a href="#Position"><em>Position</em></a>
and <a href="#Direction"><em>Direction</em></a> types. Questions or suggestions can be posted on
the Github repository.
</p>
<h3 id="Snake"><code style="color:white">Snake</code></h3>
<div style="margin-left:40px">
<p>
<em>Snake</em> is a singleton class used to expose all interesting
information about the game. <em>Snake</em> is the outward facing interface
that should be used to design cheat behaviors. If there is a piece of
information that your cheat needs that you'd like to be added to the API,
submit an issue or pull request on the Github repository.
</p>
<br>
<h4 style="color:red">Field Summary</h4>
<p>
<em>No public fields</em>
</p>
<br>
<h4 style="color:red">Method Summary</h4>
<h4 id="snake-getHeight"><code><em style="color:white">int</em> Snake.getHeight()</code></h4>
<p style="margin-left:40px">
getHeight() returns the height of the game board in tiles. When the game is loaded, the
board is resized dynamically to fit the screen.<br>
<span style="color:red">params</span> - <em>none</em><br>
<span style="color:red">return</span> - <em>integer height of board</em><br>
</p>
<br>
<h4 id="snake-getWidth"><code><em style="color:white">int</em> Snake.getWidth()</code></h4>
<p style="margin-left:40px">
getWidth() returns the width of the game board in tiles. When the game is loaded, the
board is resized dynamically to fit the screen.<br>
<span style="color:red">params</span> - <em>none</em><br>
<span style="color:red">return</span> - <em>integer width of board</em><br>
</p>
<br>
<h4 id="snake-getPositions"><code><em style="color:white">int[][]</em> Snake.getPositions()</code></h4>
<p style="margin-left:40px">
getPositions() returns a copy of the two dimensional array of size
Snake.getWidth() x Snake.getHeight() that represents all the positions on the board.
Each entry is either a 0, 1, or 2. 0 represents an empty space, 1 represents a space
filled by the snake, and 2 represents a space filled by the food.<br>
<span style="color:red">params</span> - <em>none</em><br>
<span style="color:red">return</span> - <em>copy of the 2D positions array</em><br>
</p>
<br>
<h4 id="snake-checkPosition"><code><em style="color:white">int</em> Snake.checkPosition(<em style="color:white">int</em> x, <em style="color:white">int</em> y)</code></h4>
<p style="margin-left:40px">
checkPosition() returns 0, 1, or 2 based on the x and y coordinates passed in. If the position is filled
by the snake or represents a position outside the game board (i.e. a wall), it returns 1. If the position
is filled by the food, it returns 2. Otherwise it returns 0.<br>
<span style="color:red">params</span> - <em>int</em> <span style="color:red">x</span>: horizontal position, <em>int</em> <span style="color:red">y</span>: vertical position<br>
<span style="color:red">return</span> - <em>integer state of the position</em><br>
</p>
<br>
<h4 id="snake-getPosition"><code><em style="color:white">Position</em> Snake.getPosition()</code></h4>
<p style="margin-left:40px">
getPosition() returns a copy of the Position that represents the the head of the snake.<br>
<span style="color:red">params</span> - <em>none</em><br>
<span style="color:red">return</span> - <em>Position of the head</em><br>
</p>
<br>
<h4 id="snake-getTailPosition"><code><em style="color:white">Position</em> Snake.getTailPosition()</code></h4>
<p style="margin-left:40px">
getTailPosition() returns a copy of the Position that represents the the tail of the snake.<br>
<span style="color:red">params</span> - <em>none</em><br>
<span style="color:red">return</span> - <em>Position of the tail</em><br>
</p>
<br>
<h4 id="snake-getFoodPosition"><code><em style="color:white">Position</em> Snake.getFoodPosition()</code></h4>
<p style="margin-left:40px">
getFoodPosition() returns a copy of the Position that represents the the food.<br>
<span style="color:red">params</span> - <em>none</em><br>
<span style="color:red">return</span> - <em>Position of the food</em><br>
</p>
<br>
<h4 id="snake-getLength"><code><em style="color:white">int</em> Snake.getLength()</code></h4>
<p style="margin-left:40px">
getLength() returns the length of the snake. Score can be derived from this because
the length of the snake at the start of the game is 5.<br>
<span style="color:red">params</span> - <em>none</em><br>
<span style="color:red">return</span> - <em>Integer length of the snake</em><br>
</p>
<br>
<h4 id="snake-getDirection"><code><em style="color:white">Direction</em> Snake.getDirection()</code></h4>
<p style="margin-left:40px">
getDirection() returns the current Direction in which the snake is heading.<br>
<span style="color:red">params</span> - <em>none</em><br>
<span style="color:red">return</span> - <em>current Direction of the snake</em><br>
</p>
<br>
</div>
<br>
<h3 id="Cheat"><code style="color:white">Cheat</code></h3>
<div style="margin-left:40px">
<p>
<em>Cheat</em> is a singleton class used to define the cheat behavior the
game implements. At the start of the game it is <em>undefined</em>, and the
Sideloader module loads custom JavaScript to override it. The game expects the
Cheat object to have a method Cheat.cheat() that returns a Direction. Every update,
Cheat.cheat() is called before the snake is moved. If Cheat.cheat() returns
<em>null</em>, then the snake continues in the same direction. When writing custom
behavior, the Cheat.cheat() method is the access point for your behavior.
</p>
<br>
<h4 style="color:red">Field Summary</h4>
<p>
<em>No public fields</em>
</p>
<br>
<h4 style="color:red">Method Summary</h4>
<h4 id="cheat-cheat"><code><em style="color:white">Direction</em> Cheat.cheat()</code></h4>
<p style="margin-left:40px">
cheat() returns a Direction to turn the snake.<br>
<span style="color:red">params</span> - <em>none</em><br>
<span style="color:red">return</span> - <em>Direction to turn the snake</em><br>
</p>
<br>
</div>
<br>
<h3 id="Position"><code style="color:white">Position</code></h3>
<div style="margin-left:40px">
<p>
The <em>Position</em> class is used to define a unique poisition in the 2D array
that defines the game board
</p>
<br>
<h4 style="color:red">Field Summary</h4>
<h4 id="position-x"><code><em style="color:white">int</em> x</code></h4>
<p style="margin-left:40px">
the x position in the 2D array game board.<br>
</p>
<br>
<h4 id="position-y"><code><em style="color:white">int</em> y</code></h4>
<p style="margin-left:40px">
the y position in the 2D array game board.<br>
</p>
<br>
<h4 style="color:red">Method Summary</h4>
<p>
<em>No public methods</em>
</p>
<br>
</div>
<br>
<h3 id="Direction"><code style="color:white">Direction</code></h3>
<div style="margin-left:40px">
<p>
The <em>Direction</em> class is used to define the four possible
directions the snake can be travelling: left, up, right, and down.
Note that if |x| > 0, then y must be 0, and likewise if |y| > 0, then
x must be 0. Diagonal directions are illegal values for <em>Direction</em>.
</p>
<br>
<h4 style="color:red">Field Summary</h4>
<h4 id="direction-x"><code><em style="color:white">int</em> x</code></h4>
<p style="margin-left:40px">
the x direction, -1, 0, or 1.<br>
</p>
<br>
<h4 id="direction-y"><code><em style="color:white">int</em> y</code></h4>
<p style="margin-left:40px">
the y direction, -1, 0, or 1.<br>
</p>
<br>
<h4 style="color:red">Method Summary</h4>
<p>
<em>No public methods</em>
</p>
<br>
</div>
<br><br><br><br><br><br>
</div>
</div>
</div>
</body>
</html>