-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
144 lines (112 loc) · 2.71 KB
/
script.js
File metadata and controls
144 lines (112 loc) · 2.71 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
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
$(document).ready(function() { //do this when page loads
var colorArray = [
{
color: 'green',
doAction: greenlight
},
{
color: 'red',
doAction: redlight
},
{
color: 'yellow',
doAction: yellowlight
},
{
color: 'blue',
doAction: bluelight
}];
console.log('function array: ', colorArray);
var gameArray = [];
var turnsPlayed = 0;
var current = 0;
var pushes = 0;
function getRandomColor () {
return colorArray[Math.floor(Math.random() * colorArray.length)];
}
function failSound() {
// css.changeColor();
alert('fail sound happened');
}
$(".tap-pad").click(function() {
var selectedColor = $(this).attr('data-color');
console.log('selectedColor: ', selectedColor);
if ( selectedColor !== gameArray[pushes].color ) {
failSound();
alert("Loosa! You only scored" + turnsPlayed + "nice try, for a loosa");
turnsPlayed++;
return;
}
pushes++;
if ( pushes === gameArray.length ) {
setTimeout(function () {
current = 0;
pushes = 0;
gameArray.push(getRandomColor());
goSimon();
}, 2500);
}
});
function goSimon () {
if ( gameArray.length - 1 < current ) {
return;
}
gameArray[current].doAction();
}
$("#simon-button").click(function() { // game starts
console.log('gameplay running');
gameArray.push(getRandomColor());
goSimon();
});
function greenlight() {
$("#green-button").css("background-color", "white");
setTimeout(function(){ // toggle back after 1 second
$("#green-button").css("background-color", "green");
current++;
goSimon();
},250);
};
function redlight() {
$("#red-button").css("background-color", "white");
setTimeout(function(){ // toggle back after 1 second
$("#red-button").css("background-color", "red");
current++;
goSimon();
},250);
};
function yellowlight() {
$("#yellow-button").css("background-color", "white");
setTimeout(function(){ // toggle back after 1 second
$("#yellow-button").css("background-color", "yellow");
current++;
goSimon();
},250);
};
function bluelight() {
$("#blue-button").css("background-color", "white");
setTimeout(function(){ // toggle back after 1 second
$("#blue-button").css("background-color", "blue");
current++;
goSimon();
},250);
};
});
/*alert("hello");
game starts when simon is clicked
count = 1;
color-array = [red,yellow,blue,green]
memory-array = []
color-array.random
for i = count {
light up the
}
$(document).ready(function() {
$("button").mouseover(function() {
var p = $("p#44.test").css("background-color", "yellow");
p.hide(1500).show(1500);
p.queue(function() {
p.css("background-color", "red");
});
});
});
*/