-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimon.js
executable file
·208 lines (176 loc) · 5.31 KB
/
simon.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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
function restart(e){
round=0;
array=[];
generateNext();
twinkle();
e.target.style.cursor='pointer';
e.target.innerHTML='good luck'
document.getElementById('luck').removeEventListener('click',restart);
}
function click(){
function mouseUp(e){
e.target.style.backgroundColor='';
e.target.style.color='';
if(parseInt(e.target.innerHTML)===array[round]){
if(round===array.length-1){
document.getElementById('current_streak').innerHTML=round+1;
generateNext();
twinkle();
round=0;
}else{
round++;
}
}else{
document.getElementById('luck').innerHTML='you failed,click here to restart';
document.getElementById('luck').addEventListener('click',restart);
if(parseInt(document.getElementById('current_streak').innerHTML)>parseInt(document.getElementById('best_streak').innerHTML)){
document.getElementById('best_streak').innerHTML=document.getElementById('current_streak').innerHTML;
}
document.getElementById('current_streak').innerHTML=0;
}
}
function mouseDownRed(){
red.style.backgroundColor='black';
red.style.color='black';
}
function mouseDownBlue(){
blue.style.backgroundColor='black';
blue.style.color='black';
}
function mouseDownGreen(){
green.style.backgroundColor='black';
green.style.color='black';
}
function mouseDownYellow(){
yellow.style.backgroundColor='black';
yellow.style.color='black';
}
/*
function redOver(){
red.style.width='250px';
red.style.height='250px';
}
function redOut(){
red.style.width='200px';
red.style.height='200px';
}
red.addEventListener('mouseover',redOver);
red.addEventListener('mouseout',redOut);
*/
red.addEventListener('mouseup',mouseUp);
red.addEventListener('mousedown',mouseDownRed);
blue.addEventListener('mouseup',mouseUp);
blue.addEventListener('mousedown',mouseDownBlue);
green.addEventListener('mouseup',mouseUp);
green.addEventListener('mousedown',mouseDownGreen);
yellow.addEventListener('mouseup',mouseUp);
yellow.addEventListener('mousedown',mouseDownYellow);
}
function generateNext(){
let random=Math.floor(Math.random()*3);
array.push(random);
/*
if(random===0){
array.push('red');
}else if(random===1){
array.push('blue');
}else if(random===2){
array.push('green');
}else{
array.push('yellow');
}
*/
}
//0:red 1:blue 2:green 3:yellow
function twinkle(){
for(let i=0;i<array.length;i++){
if(array[i]===0){
setTimeout(function(){
red.style.backgroundColor='black';
red.style.color='black';
},flashlightTime*i+intervalTime*i+newRoundTime);
setTimeout(function(){
red.style.backgroundColor='';
red.style.color='';
},flashlightTime*(i+1)+intervalTime*i+newRoundTime);
}else if(array[i]===1){
setTimeout(function(){
blue.style.backgroundColor='black';
blue.style.color='black';
},flashlightTime*i+intervalTime*i+newRoundTime);
setTimeout(function(){
blue.style.backgroundColor='';
blue.style.color='';
},flashlightTime*(i+1)+intervalTime*i+newRoundTime);
}else if(array[i]===2){
setTimeout(function(){
green.style.backgroundColor='black';
green.style.color='black';
},flashlightTime*i+intervalTime*i+newRoundTime);
setTimeout(function(){
green.style.backgroundColor='';
green.style.color='';
},flashlightTime*(i+1)+intervalTime*i+newRoundTime);
}else{
setTimeout(function(){
yellow.style.backgroundColor='black';
yellow.style.color='black';
},flashlightTime*i+intervalTime*i+newRoundTime);
setTimeout(function(){
yellow.style.backgroundColor='';
yellow.style.color='';
},flashlightTime*(i+1)+intervalTime*i+newRoundTime);
}
}
}
let round=0;
let red=document.getElementById('red');
let blue=document.getElementById('blue');
let green=document.getElementById('green');
let yellow=document.getElementById('yellow');
let flashlightTime=250;
let intervalTime=250;
let newRoundTime=500;
let array=[];
generateNext();
twinkle();
click();
/*
function redCheck(){
}
/*
let generateNextColor=function(){
let randomNum=Math.floor(Math.random()*4);
if(randomNum===0){
red.style.backgroundColor='black';
setTimeout(function(){red.style.backgroundColor='';},flashlightTime);
array.push('red');
}else if(randomNum===1){
blue.style.backgroundColor='black';
setTimeout(function(){blue.style.backgroundColor='';},flashlightTime);
array.push('blue');
}else if(randomNum===2){
green.style.backgroundColor='black';
setTimeout(function(){green.style.backgroundColor='';},flashlightTime);
array.push('green');
}else{
yellow.style.backgroundColor='black';
setTimeout(function(){yellow.style.backgroundColor='';},flashlightTime);
array.push('yellow');
}
}
let checkArray=function(array){
let click;
for(let i=0;i<array.length.i++){
click=red.onclick(function(){return 'red'});
}
}
let checkClick=function(str){
let strCheck,redCheck,blueCheck,greenCheck,yellowCheck;
strCheck=document.getElementById(str).onclick(function()=>{return true});
if('red'!==str)
redCheck=document.getElementById('red').onclick(function()=>{return false});
}
generateNextColor();
checkArray(array);
*/