-
Notifications
You must be signed in to change notification settings - Fork 0
/
snake1.html
166 lines (143 loc) · 9.43 KB
/
snake1.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var length = [".52",".53"];
var i;
var j=1;
var m;
var count=0;
var l=1;
function makeFood()
{
m=".";
m=m+Math.floor(Math.random()*10)+Math.floor(Math.random()*10);
if(length.includes(m))
{m=".";makeFood();}
$(m).attr("style","background-color:red;");
$("h4").text(m);
}
$(document).keydown(function(e){
if(j==1)
{makeFood();}
var key = e.which;
if(key == "37" && l != "r") l = "left";
else if(key == "38" && l != "d") l = "u";
else if(key == "39" && l != "left") l = "r";
else if(key == "40" && l != "u") l = "d";
if(l=="r" || l=="left")
{i=length[length.length-1];i=i.slice(2,3);}
if(l=="u" || l=="d")
{i=length[length.length-1];i=i.slice(1,2);i=Number(i);}
IncDec(l);
clearTimeout(count);
move();
});
function IncDec(q)
{
switch(q)
{
case "u":i--;break
case "r":i++;break;
case "left":i--;break;
case "d":i++;break;
}
}
function trimming()
{
if(l=="r" || l=="left")
{j=j.slice(0, 2);j=j+i;}
if(l=="u" || l=="d")
{j=j.slice(2, 3);j="."+i+j;}
}
function checkCondition()
{
if(i>9)
i=0;
if(i<0)
i=9;
}
function move()
{
clearTimeout(count);
checkCondition();
j=length.shift();
$(j).attr("style","background-color:black;");
j=length[length.length-1];
trimming();
clearTimeout(count);
if(length.includes(j) && l!=1)
{alert("game Over");location.reload();}
length.push(j);$(j).attr("style","background-color:yellow;border: 2px solid white;");
if(j==m)
{IncDec(l);checkCondition();trimming();length.push(j);$(j).attr("style","background-color:yellow;border: 2px solid white;");makeFood();$("h1").text("Score - "+(length.length-2));}
IncDec(l);
var z=length.toString();
$("p").text(z);
count=setTimeout(move,220);
}
});
</script>
<style>
.col-md-1
{height:50px;width:50px;padding-left:16px;padding-top:2px;}
h3
{
float:right;position: absolute;top:80px;right:0px;
}
</style>
</head>
<body>
<h4>sdd</h4>
<p>setTimeout(function(){move(l)}, 1000);</p>
<div class="container" style=" padding-left: 200px;">
<div class="row">
<div class="col-md-1 00" style="background-color:black;"></div><div class="col-md-1 01" style="background-color:black;"></div><div class="col-md-1 02" style="background-color:black;"></div><div class="col-md-1 03" style="background-color:black;"></div><div style="background-color:black;" class="col-md-1 04"></div><div style="background-color:black;" class="col-md-1 05"></div><div style="background-color:black;" class="col-md-1 06"></div><div style="background-color:black;" class="col-md-1 07"></div><div style="background-color:black;" class="col-md-1 08"></div><div style="background-color:black;" class="col-md-1 09"></div>
</div>
<div class="row">
<div class="col-md-1 10" style="background-color:black;"></div><div class="col-md-1 11" style="background-color:black;"></div><div class="col-md-1 12" style="background-color:black;"></div><div class="col-md-1 13" style="background-color:black;"></div><div class="col-md-1 14" style="background-color:black;"></div><div class="col-md-1 15" style="background-color:black;"></div><div class="col-md-1 16" style="background-color:black;"></div><div class="col-md-1 17" style="background-color:black;"></div><div class="col-md-1 18" style="background-color:black;"></div><div class="col-md-1 19" style="background-color:black;"></div>
</div>
<div class="row">
<div class="col-md-1 20" style="background-color:black;"></div><div class="col-md-1 21" style="background-color:black;"></div><div class="col-md-1 22" style="background-color:black;"></div><div class="col-md-1 23" style="background-color:black;"></div><div class="col-md-1 24" style="background-color:black;"></div><div class="col-md-1 25" style="background-color:black;"></div><div class="col-md-1 26" style="background-color:black;"></div><div class="col-md-1 27" style="background-color:black;"></div><div class="col-md-1 28" style="background-color:black;"></div><div class="col-md-1 29" style="background-color:black;"></div>
</div>
<div class="row">
<div class="col-md-1 30" style="background-color:black;"></div><div class="col-md-1 31" style="background-color:black;"></div><div class="col-md-1 32" style="background-color:black;"></div><div class="col-md-1 33" style="background-color:black;"></div><div class="col-md-1 34" style="background-color:black;"></div><div class="col-md-1 35" style="background-color:black;"></div><div class="col-md-1 36" style="background-color:black;"></div><div class="col-md-1 37" style="background-color:black;"></div><div class="col-md-1 38" style="background-color:black;"></div><div class="col-md-1 39" style="background-color:black;"></div>
</div>
<div class="row">
<div class="col-md-1 40" style="background-color:black;"></div><div class="col-md-1 41" style="background-color:black;"></div><div class="col-md-1 42" style="background-color:black;"></div><div class="col-md-1 43" style="background-color:black;"></div><div class="col-md-1 44" style="background-color:black;"></div><div class="col-md-1 45" style="background-color:black;"></div><div class="col-md-1 46" style="background-color:black;"></div><div class="col-md-1 47" style="background-color:black;"></div><div class="col-md-1 48" style="background-color:black;"></div><div class="col-md-1 49" style="background-color:black;"></div>
</div>
<div class="row">
<div class="col-md-1 50" style="background-color:black;"></div><div class="col-md-1 51" style="background-color:black;"></div><div class="col-md-1 52" style="background-color:yellow;border: 2px solid white;"></div><div class="col-md-1 53" style="background-color:yellow;border: 2px solid white;"></div><div class="col-md-1 54" style="background-color:black;"></div><div class="col-md-1 55" style="background-color:black;"></div><div class="col-md-1 56" style="background-color:black;"></div><div class="col-md-1 57" style="background-color:black;"></div><div class="col-md-1 58" style="background-color:black;"></div><div class="col-md-1 59" style="background-color:black;"></div>
</div>
<div class="row">
<div class="col-md-1 60" style="background-color:black;"></div><div class="col-md-1 61" style="background-color:black;"></div><div class="col-md-1 62" style="background-color:black;"></div><div class="col-md-1 63" style="background-color:black;"></div><div class="col-md-1 64" style="background-color:black;"></div><div class="col-md-1 65" style="background-color:black;"></div><div class="col-md-1 66" style="background-color:black;"></div><div class="col-md-1 67" style="background-color:black;"></div><div class="col-md-1 68" style="background-color:black;"></div><div class="col-md-1 69" style="background-color:black;"></div>
</div>
<div class="row">
<div class="col-md-1 70" style="background-color:black;"></div><div class="col-md-1 71" style="background-color:black;"></div><div class="col-md-1 72" style="background-color:black;"></div><div class="col-md-1 73" style="background-color:black;"></div><div class="col-md-1 74" style="background-color:black;"></div><div class="col-md-1 75" style="background-color:black;"></div><div class="col-md-1 76" style="background-color:black;"></div><div class="col-md-1 77" style="background-color:black;"></div><div class="col-md-1 78" style="background-color:black;"></div><div class="col-md-1 79" style="background-color:black;"></div>
</div>
<div class="row">
<div class="col-md-1 80" style="background-color:black;"></div><div class="col-md-1 81" style="background-color:black;"></div><div class="col-md-1 82" style="background-color:black;"></div><div class="col-md-1 83" style="background-color:black;"></div><div class="col-md-1 84" style="background-color:black;"></div><div class="col-md-1 85" style="background-color:black;"></div><div class="col-md-1 86" style="background-color:black;"></div><div class="col-md-1 87" style="background-color:black;"></div><div class="col-md-1 88" style="background-color:black;"></div><div class="col-md-1 89" style="background-color:black;"></div>
</div>
<div class="row">
<div class="col-md-1 90" style="background-color:black;"></div><div class="col-md-1 91" style="background-color:black;"></div><div class="col-md-1 92" style="background-color:black;"></div><div class="col-md-1 93" style="background-color:black;"></div><div class="col-md-1 94" style="background-color:black;"></div><div class="col-md-1 95" style="background-color:black;"></div><div class="col-md-1 96" style="background-color:black;"></div><div class="col-md-1 97" style="background-color:black;"></div><div class="col-md-1 98" style="background-color:black;"></div><div class="col-md-1 99" style="background-color:black;"></div>
</div>
</div>
<h1>Score - 0</h1>
<h3>
<b>Instructions</b><br><br>
1.Use Direction key to move the snake <br>
2.Eat food (red in color) to increase score<br>
3.Eating food also increase length of snake<br>
4.Game will be over if you hit your own body ....<br><br>
........................ALL THE BEST.........................
</h3>
</body>
</html>