-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (38 loc) · 1.26 KB
/
app.js
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
//Using module pattern for keeping global space clean and maintain modular code.
var app = (function() {
var direction = "right";
return {
/**
* Initialize the app
*/
init: function () {
var mySnake = new snake();
mySnake.init();
$("#fullscreen").click(function(){
mySnake.fullScreen();
});
$("#restart").click(function(){
mySnake.restart();
});
document.addEventListener("fullscreenchange", function(){mySnake.setOffsetForFullScreen();});
document.addEventListener("webkitfullscreenchange", function(){mySnake.setOffsetForFullScreen();});
document.addEventListener("mozfullscreenchange", function(){mySnake.setOffsetForFullScreen();});
document.addEventListener("MSFullscreenChange", function(){mySnake.setOffsetForFullScreen();});
}
};
}());
$(document).ready(function(){
app.init();
$(document).keydown(function(e){
var key = e.which;
if(key == "37" && direction != "right") {
direction = "left";
} else if(key == "38" && direction != "down") {
direction = "up";
} else if(key == "39" && this.direction != "left") {
direction = "right";
} else if(key == "40" && direction != "up") {
direction = "down";
}
});
});