forked from gaarf/game-of-snake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
59 lines (51 loc) · 1.49 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
<html>
<head>
<title>SNAKE GAME!</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="snake.js"></script>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function() {
var bearing
, iter = 0
, $world = $('#world')
, $score = $('#score')
, game = new Game({h:20, w:30});
function cycle() {
game.iterate(bearing);
bearing = null;
if(game.isOver()) {
$('#gameover').appendTo($world).show().focus();
return;
}
$score.find('.iter').text(iter++);
$score.find('.tail').text(game.snake.tail.length);
$score.find('.appl').text(game.grid.apples);
$score.find('.level').text(game.level);
$world.html(game.toHtml());
setTimeout(cycle, game.delay);
}
$(document).on('keydown', function(ev){
bearing = {38:'N',39:'E',40:'S',37:'W'}[ev.which];
if(bearing) {
ev.preventDefault();
}
});
cycle();
});
</script>
</head>
<body>
<div id="world"></div>
<ul id="score">
<li>Iteration <em class="iter">0</em></li>
<li>Tail length <em class="tail">0</em></li>
<li>Remaining apples <em class="appl">0</em></li>
<li>Level <em class="level">1</em></li>
</ul>
<a href="javascript:location.reload()" id="gameover">
<strong>GAME OVER</strong><br>
<span>click to play again!</span>
</a>
</body>
</html>