-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjogo2.js
More file actions
199 lines (199 loc) · 5.04 KB
/
jogo2.js
File metadata and controls
199 lines (199 loc) · 5.04 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
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
var CSS_COLOR_NAMES = [
"AliceBlue",
"AntiqueWhite",
"Aqua",
"Aquamarine",
"Azure",
"Beige",
"Bisque",
"Black",
"BlanchedAlmond",
"Blue",
"BlueViolet",
"Brown",
"BurlyWood",
"CadetBlue",
"Chartreuse",
"Chocolate",
"Coral",
"CornflowerBlue",
"Cornsilk",
"Crimson",
"Cyan",
"DarkBlue",
"DarkCyan",
"DarkGoldenRod",
"DarkGray",
"DarkGrey",
"DarkGreen",
"DarkKhaki",
"DarkMagenta",
"DarkOliveGreen",
"DarkOrange",
"DarkOrchid",
"DarkRed",
"DarkSalmon",
"DarkSeaGreen",
"DarkSlateBlue",
"DarkSlateGray",
"DarkSlateGrey",
"DarkTurquoise",
"DarkViolet",
"DeepPink",
"DeepSkyBlue",
"DimGray",
"DimGrey",
"DodgerBlue",
"FireBrick",
"FloralWhite",
"ForestGreen",
"Fuchsia",
"Gainsboro",
"GhostWhite",
"Gold",
"GoldenRod",
"Gray",
"Grey",
"Green",
"GreenYellow",
"HoneyDew",
"HotPink",
"IndianRed",
"Indigo",
"Ivory",
"Khaki",
"Lavender",
"LavenderBlush",
"LawnGreen",
"LemonChiffon",
"LightBlue",
"LightCoral",
"LightCyan",
"LightGoldenRodYellow",
"LightGray",
"LightGrey",
"LightGreen",
"LightPink",
"LightSalmon",
"LightSeaGreen",
"LightSkyBlue",
"LightSlateGray",
"LightSlateGrey",
"LightSteelBlue",
"LightYellow",
"Lime",
"LimeGreen",
"Linen",
"Magenta",
"Maroon",
"MediumAquaMarine",
"MediumBlue",
"MediumOrchid",
"MediumPurple",
"MediumSeaGreen",
"MediumSlateBlue",
"MediumSpringGreen",
"MediumTurquoise",
"MediumVioletRed",
"MidnightBlue",
"MintCream",
"MistyRose",
"Moccasin",
"NavajoWhite",
"Navy",
"OldLace",
"Olive",
"OliveDrab",
"Orange",
"OrangeRed",
"Orchid",
"PaleGoldenRod",
"PaleGreen",
"PaleTurquoise",
"PaleVioletRed",
"PapayaWhip",
"PeachPuff",
"Peru",
"Pink",
"Plum",
"PowderBlue",
"Purple",
"RebeccaPurple",
"Red",
"RosyBrown",
"RoyalBlue",
"SaddleBrown",
"Salmon",
"SandyBrown",
"SeaGreen",
"SeaShell",
"Sienna",
"Silver",
"SkyBlue",
"SlateBlue",
"SlateGray",
"SlateGrey",
"Snow",
"SpringGreen",
"SteelBlue",
"Tan",
"Teal",
"Thistle",
"Tomato",
"Turquoise",
"Violet",
"Wheat",
"White",
"WhiteSmoke",
"Yellow",
"YellowGreen",
];
function iniciarJogo() {
var cores = CSS_COLOR_NAMES;
var vetorCores = [];
var bool; // utilizado no loop
var corUsuario; //cor escolhida pelo usuário
var vidas = 5;
while (vetorCores.length < 10) {
vetorCores[vetorCores.length] = cores[Math.floor(Math.random() * (cores.length - 1)) + 1];
vetorCores = vetorCores.filter(function (v, i, a) { return a.indexOf(v) === i; });
}
//preenche o vetor de cores randomicamente e impede a duplicidade de valores.
vetorCores.sort(); // ordena as cores alfabeticamente
var corEscolhida = Math.floor(Math.random() * (vetorCores.length - 1)) + 1; //escolhe aleatóriamente uma posição do vetor cores
var vetorCores2 = vetorCores.map(function (vetorCores) { return vetorCores.toUpperCase(); }); //cria um novo vetor cores para MAISCULO.
while (!bool) {
corUsuario = prompt("Eu estou pensando em uma dessas cores: \n" + vetorCores.join(', ') + "\nEm qual delas eu estou pensando?\n" + "Voc\u00EA tem ".concat(vidas, " vidas restantes"));
corUsuario = corUsuario.toUpperCase(); //cor do usuário para MAIUSCULO
if (vidas == 0) {
bool = true;
document.getElementById("msg").innerHTML = "Tente novamente.";
alert("Vidas esgotadas\nFim de jogo.");
}
else {
if (vetorCores2.indexOf(corUsuario) < 0) {
alert("Cor inexistente");
}
else {
if (corUsuario == vetorCores2[corEscolhida]) {
alert("Você acertou!");
bool = true;
document.body.style.background = corUsuario;
document.getElementById("msg").innerHTML = "A cor \u00E9: ".concat(vetorCores[corEscolhida]);
}
else {
var res = corUsuario.localeCompare(vetorCores2[corEscolhida]);
var dica = "Dica: a cor escolhida é alfabeticamente ";
if (res == -1) {
dica += "maior do que a que você escolheu";
}
else {
dica += "menor do que a que você escolheu";
}
vidas--;
alert("Desculpe! Sua resposta n\u00E3o est\u00E1 correta!\n".concat(dica, "\nPor favor tente novamente."));
}
}
}
}
}