-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
167 lines (144 loc) · 5.58 KB
/
index.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
167
<!DOCTYPE html>
<html>
<head>
<title>Click me if you can!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
//Public declarations
var timesClicked = 0;
var x = 375;
var y = 225;
var frame = 0;
var anim;
var isFinished = true;//Makes animation go till the end if button is clicked/entered in the process
var frameCount = 16;
var clicked = false;//Adds ability to perform the first click
//Makes one frame of animation
function createPath(xx,yy){
document.getElementById("button").style.left = xx+"px";
document.getElementById("button").style.top = yy+"px";
frame++;
if (frame == frameCount)
{
clearInterval(anim);
isFinished = true;
};
}
function startGame(difficulty){
frameCount = difficulty;
document.getElementById("difficultyMenu").style.display = "none";
document.getElementById("button").style.display = "block";
document.getElementById("restart").style.display = "block";
document.getElementById("button").style.left = "375px";
document.getElementById("button").style.top = "225px";
clicked = false;
};
function restartGame(){
document.getElementById("difficultyMenu").style.display = "block";
document.getElementById("button").style.display = "none";
document.getElementById("restart").style.display = "none";
x = 375;
y = 225;
timesClicked = 0;
document.getElementById("info").innerHTML = timesClicked;
isFinished = true;
frameCount = 16;
}
function changePosition(){
if (clicked) {
var x0 = x;
//Chooses random position not too close from previous one
do{
x = Math.random()*748+1;
}
while (Math.abs(x-x0)<50)
var dx = (x - x0) / frameCount;
var y0 = y;
do{
y = Math.random()*447+1;
}
while (Math.abs(y-y0)<50 && (x>700 && y<20))
var dy = (y - y0) / frameCount;
//Animation initialisation
frame = 0;
isFinished = false;
anim = setInterval(function() {createPath(x0+dx*(frame+1),y0+dy*(frame+1))}, 20);
};
};
window.onload = function(){
var button = document.getElementById("button");
//Adding restart button
document.getElementById("restart").onclick = function(){restartGame()};
//Assigning difficulties
document.getElementById("easy").onclick = function(){startGame(20)};
document.getElementById("medium").onclick = function(){startGame(16)};
document.getElementById("hard").onclick = function(){startGame(12)};
//Moving div as soon as mouse enters div
button.onmouseover = function(){
if (isFinished) {
changePosition();
}
};
//Moving div and increasing counter if "button" is pressed
button.onclick=function(){
timesClicked++;
document.getElementById("info").innerHTML = timesClicked;
clicked = true;
if (isFinished){
changePosition();
};
};
};
</script>
</head>
<body style="background:#E0E0A5">
<h2 align="center" style="font-family:Geneva, Arial, Helvetica, sans-serif; margin-top:15px; margin-bottom:15px; padding:0px">The Great Clicking Game</h2>
<!--Frame div, that makes visual border-->
<div style="border: 5px dashed #E0E0A5; width: 800px; height: 500px; margin:0px; padding:0px; margin-left: auto; margin-right: auto; background-color:#FFFDBB;
/*User cannot select text BEGIN*/
-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;
/* END */">
<div id="restart" style="float:right; font-weight:bold; cursor:pointer; margin-right:5px; position:relative; font-size:13px; display:none">
Restart
</div>
<!--Button styled div that we need to click. Doesn't change cursor style, doesn't have any link.-->
<div style="margin: 0px; height: 50px; width: 50px; background-color: rgb(0, 0, 102); text-align: center; cursor:default; position: relative;
border-radius:5px; left: 375px; top: 225px; display: none;" id="button">
<p style="vertical-align: middle; font-family: Comic Sans MS,Verdana; color: rgb(255, 255, 255); font-weight:bold;
margin: 0px; padding:0px">
Click me!
</p>
</div>
<!--Button END-->
<!--Menu with difficulty choice - different frame count in the animation-->
<div style="height:100px; width:274px; top:200px; left:262px; position:relative; background-color:#D3D29B; font-weight:bold; cursor: default;
font-size: 18px; border:5px dashed #FFFDBB"
id="difficultyMenu">
<p style="font-family:Geneva, Arial, Helvetica, sans-serif; padding-top:10px; text-align:center; margin-bottom:10px; margin-top:0px; font-size:19px">
Select difficulty level!
</p>
<div style="border-radius:5px; background-color:green; cursor:pointer; float:left; height:40px; width:80px; margin:3px; margin-left:11px" id="easy">
<p style="padding-top:8px; text-align:center; font-family: Geneva, Arial, Helvetica, sans-serif; color: rgb(255, 255, 255); margin:0px;">
Easy
</p>
</div>
<div style="border-radius:5px; background-color:blue; cursor:pointer; float:left; height:40px; width:80px; margin:3px" id="medium">
<p style="padding-top:8px; text-align:center; font-family: Geneva, Arial, Helvetica, sans-serif; color: rgb(255, 255, 255); margin:0px;">
Medium
</p>
</div>
<div style="border-radius:5px; background-color:red; cursor:pointer; float:left; height:40px; width:80px; margin:3px" id="hard">
<p style="padding-top:8px; text-align:center; font-family: Geneva, Arial, Helvetica, sans-serif; color: rgb(255, 255, 255); margin:0px;">
Hard
</p>
</div>
</div>
<!--Difficulty menu END-->
</div>
<!--Frame div END-->
<!--Counter-->
<div align="center" style="font-family:Geneva, Arial, Helvetica, sans-serif; margin-top: 10px; font-weight:bold">
Times clicked so far: <div id="info" style="display:inline">0</div>
</div>
</body>
</html>