-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
134 lines (96 loc) · 2.49 KB
/
index.js
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
var colors = ["green", "red", "orange", "yellow", "blue", "purple"];
var index = 0;
var started = false;
var audio;
var isrunning=true;
var b=[];
var i=0;
var ispressing=true;
var finalmusic=true;
$("#clickable").click(function() {
finalmusic=false;
isrunning=true;
if (!started) {
$("h1").text("Close your eyes and press k key!");
audio = new Audio("gamemusic.wav");
audio.play();
rotation();
started = true;
ispressing=true;
}
});
function rotation() {
if(isrunning){
if (index < 6) {
$("#" + colors[index]).addClass('going');
setTimeout(function() {
$("#" + colors[index]).removeClass('going');
index++;
rotation();
}, 250);
} else {
index = 0;
rotation();// Reset index after completing a rotation
}
}
}
$(document).keydown(function(event) {
if(ispressing){
if($(".btn").length===2){
$("h1").text("HERE is your final character");
var k=new Audio("gamemusic.wav");
if(finalmusic==true){
k.play();
finalmusic=false;
}
}else{
$("h1").text("Now one of your fav characters will disappear,click again and play,till only one of them is left");
}
isrunning=false;
if (audio) {
audio.pause();
audio.currentTime = 0; // Reset audio to the beginning
}
addingpress();
started = false;
if($(".btn").length==1){
$("h1").text("HERE is your character! click on it to know more!");
}
ispressing=false;
}
});
function check(rando,b,i){
for(var j=0;j<i;j++){
if(rando==b[j]){
return 0;
}
}
return 1;
}
function addingpress(){
var rando = Math.floor(Math.random() * (6));
if(check(rando,b,i)==1){
$("#" + colors[rando]).addClass('pressed');
b[i]=rando;
i++;
setTimeout(function(){
if(rando===0){
$("#" + colors[0]).remove();
}
else if(rando===1){
$("#" + colors[1]).remove();
}else if(rando===2){
$("#" + colors[2]).remove();
}else if(rando===3){
$("#" + colors[3]).remove();
}else if(rando===4){
$("#" + colors[4]).remove();
}else if(rando===5){
$("#" + colors[5]).remove();
}
},2000)
}else{
var rando = Math.floor(Math.random() * (6));
addingpress();
}
}