-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.html
90 lines (80 loc) · 2.3 KB
/
game.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
<!DOCTYPE html>
<html lang="en" style="width: 100%; height: 100%">
<head>
<meta charset="UTF-8">
<title>贪吃蛇</title>
<link href="./css/main.css" rel="stylesheet"/>
</head>
<body>
<div class="main" style="position: relative">
<img src="./img/start/bg.png" style="width: 100%; height: 100%">
<div class="main-bg">
<img src="img/start/base-bg.png" style="width: 100%; height: 100%"/>
<canvas id="snake-main" style="width: 100%; height: 100%; position: absolute; left:0; top: 0;">
</canvas>
<div id="ready" style="width: 100%; height: 100%; position: absolute; top: 0; left: 0; display: none;">
<div style="display: table-cell; vertical-align: middle; text-align: center">
<img src="./img/start/ready.png" style="width: 15%"/>
</div>
</div>
<div id="go" style="width: 100%; height: 100%; position: absolute; top: 0; left: 0; display: none;">
<div style="display: table-cell; vertical-align: middle; text-align: center">
<img src="./img/start/go.png" style="width: 10%"/>
</div>
</div>
</div>
</div>
</body>
<script src="./bower_components/zepto/zepto.min.js"></script>
<script src="./js/common.js"></script>
<script src="./js/snake.js"></script>
<script>
document.body.addEventListener('touchmove', function(evt) {
if(!evt._isScroller) {
evt.preventDefault();
}
});
var _snake;
$(function(){
init($(".main")[0]);
show_ready();
});
function show_ready() {
$("#ready").css("display", "table");
setTimeout("show_go()", 1000);
}
function show_go() {
$("#ready").hide();
$("#go").css("display", "table");
setTimeout("lets_go()", 1000);
}
function lets_go(){
$("#go").hide();
snake_game();
}
function snake_game(){
var width = $(".main-bg").width();
var height = $(".main-bg").height();
_snake = new snake();
_snake.init({
width: height,
height: width,
is_flip: true,
canvas: $("#snake-main")[0],
change_score: change_score,
game_over: game_over
});
_snake.start(_snake);
}
function change_score(score) {
console.log(score);
}
function game_over(score) {
if(score < 10){
window.location.href="./share.html?s="+score;
}else{
window.location.href="./go-game.html?s="+score;
}
}
</script>
</html>