-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
81 lines (61 loc) · 1.34 KB
/
main.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
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
var snake;
var code;
var food;
var timer;
var count=0;
function init()
{
food=new Food();
snake=new Snake();
food.show();
snake.show();
snake.move();
timer=setInterval('snake.move()',200);
}
window.onload=function()
{
init();
document.onkeydown=function(event)
{
if(window.event)
code=window.event.keyCode;
else{
code=event.keyCode;
}
snake.setDirective(code);
if(code==80){
//这个游戏需要暂停
//再按一下游戏继续
count++;
if(count%2!=0)
{
clearInterval(timer);
document.getElementById('over').style.display='block';
document.getElementById('over').innerHTML='Pause';
}else{
timer=setInterval('snake.move()',200);
document.getElementById('over').style.display='none';
}
}
}
document.getElementById('over').onclick=function()
{
this.style.display='none';
//蛇应该是从一开始的地方开始动了
//init();
remove();
init();
}
}
function remove()
{
var map=document.getElementById('map');
var childs=map.childNodes;
//map.removeChild(childs[1]);
//map.removeChild(childs[2]);
//map.removeChild(childs[3]);
//map.removeChild(childs[4]);
for(var i = childs.length - 1; i >= 0; i--) {
map.removeChild(childs[i]);
}
}