-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.html
105 lines (99 loc) · 1.96 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html>
<head>
<title>jquery</title>
<style>
#main{
height: 600px;
width:1000px;
background:#cccccc;
position: relative;
margin:5px;
border:groove;
padding: 5px;
border-radius: 10px;
border-color:transparent;
}
.boll{
height:40px;
width:40px;
border-radius: 50%;
text-align: center;
position: absolute;
background-color:red;
}
#scor_board{
height: 605px;
width:234px;
background-color: #c5c5c5;;
margin-left:1009px;
border-radius: 10px;
padding: 5px;
}
</style>
<script type="text/javascript" src="jquery-3.3.1.slim.min.js"></script>
<script type="text/javascript">
scr=0;
function rand() {
color_arr=["yellow","green","blue","pink","#990023","orange","cyan"]
n=Math.round(Math.random()*15);
for(i=0;i<=n;i++)
{
val=Math.round(Math.random()*9);
x=Math.round(Math.random()*950)
y=Math.round(Math.random()*550)
$('#main').append("<div class='boll' style='left:"+x+"px"+";top:"+y+"px"+";background-color:"+color_arr[i]+"' onclick='clk(this)'><h3>"+val+"</h3></div>");
}
$("#scor_board").html("<h1>Score:"+scr+"</h1>");
}
function clk(t)
{
$(t).remove();
n--;
if(n==-1)
rand();
}
function mov()
{
arr=$('.boll');
for(i=0;i<arr.length;i++)
{
v=String(arr[i].style.top).split("px");
if(v[0]<570)
v[0]=Number(v[0])+3;
arr[i].style.top=v[0]+"px";
if(v[0]>=570)
{
$(arr[i]).remove();
}
}
if(arr.length==0)
{
rand();
}
}
function down(ev)
{
key=String.fromCharCode(ev.keyCode)
arr=$('.boll');
for(j=0;j<arr.length;j++)
{
txt=$(arr[j]).text();
if(key==txt)
{
scr+=Number(key);
$("#scor_board").html("<h1>Score:"+scr+"</h1>");
$(arr[j]).remove();
}
}
}
window.setInterval("mov()",10)
</script>
</head>
<body onload="rand()" onkeydown="down(event)">
<div id="main">
<div id="scor_board">
</div>
</div>
</body>
</html>