-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (65 loc) · 2.37 KB
/
script.js
File metadata and controls
71 lines (65 loc) · 2.37 KB
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
document.getElementById("final-box").style.display = "none";
var sec = 0,mSec = 0;
var max = 0;
var isClicked = false;
var start;
var bestScore = 10000;
figureGenerator();
document.getElementById("shape").addEventListener("click",showTime);
document.getElementById("end").addEventListener("click",endGame);
var myVar;
function fig(){
document.getElementById("shape").style.display = "none";
setTimeout(figureGenerator,700);
}
function figureGenerator(){
start = new Date().getTime();
var value = Math.random();
var color = getRandomColor();
var width = Math.floor(value*500 + 10);
if(width<50)
width+= 100;
else if(width>300)
width-=50;
document.getElementById("shape").style.width = width+"px";
document.getElementById("shape").style.height = width+"px";
document.getElementById("shape").style.marginLeft = Math.random()*700+"px";
document.getElementById("shape").style.marginTop = Math.random()*300+"px";
if(value>0.6 && max<3){
document.getElementById("shape").style.borderRadius = (width)/2 + "px";
max++;
}else{
document.getElementById("shape").style.borderRadius = "0px";
max = 0;
}
document.getElementById("shape").style.backgroundColor = color;
document.getElementById("shape").style.display = "block";
}
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
if(color == "#FFFFFF")
getRandomColor();
return color;
}
function showTime(){
var end = new Date().getTime();
var time = (end-start)/1000;
document.getElementById("timer").innerHTML = "Time Taken: " + time+"s";
if(bestScore>time)
bestScore = time;
fig();
}
function endGame(){
document.getElementById("sub-heading").style.display = "none";
document.getElementById("timer").style.display = "none";
document.getElementById("shape").style.display = "none";
document.getElementById("end").style.display = "none";
document.getElementById("page").style.display = "none";
document.getElementById("final-box").style.display = "block";
document.getElementById("end-result").innerHTML = "Game Over!";
document.getElementById("final").innerHTML = "Your Best Score: " + bestScore+"s";
}