-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolor-game.html
More file actions
383 lines (332 loc) ยท 13.2 KB
/
color-game.html
File metadata and controls
383 lines (332 loc) ยท 13.2 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Color Matching Game</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Comic Sans MS', Arial, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
height: 100vh;
overflow: hidden;
transition: background 0.5s ease;
cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="48" height="68" viewBox="0 0 24 34"><path d="M3 2 L3 26 L9 20 L13 30 L17 28 L13 18 L21 18 Z" fill="white" stroke="black" stroke-width="1.5"/></svg>') 0 0, auto;
}
/* Montessori Mode */
body.montessori {
background: #f5f1eb;
font-family: 'Georgia', serif;
}
body.montessori #message {
background: rgba(93, 78, 55, 0.8);
font-size: 32px;
}
body.montessori #score {
background: rgba(93, 78, 55, 0.7);
}
body.montessori #menu-button {
background: rgba(93, 78, 55, 0.7);
}
body.montessori #color-display {
box-shadow: 0 4px 15px rgba(93, 78, 55, 0.15);
}
body.montessori .color-item {
box-shadow: 0 4px 12px rgba(93, 78, 55, 0.15);
}
body.montessori .color-item:hover {
transform: scale(1.03);
}
body.montessori .rainbow {
display: none;
}
body.montessori .celebration {
display: none;
}
/* Large hand cursor for all clickable elements */
a, button, .color-item, [onclick], *[role="button"] {
cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="56" height="72" viewBox="0 0 28 36"><path d="M8 0 L8 11 L6 11 L6 4 L4 4 L4 13 L2 13 L2 6 L0 6 L0 18 C0 18 0 20 2 20 L6 20 L6 28 C6 30 8 32 10 32 L16 32 C18 32 20 30 20 28 L20 16 L18 14 L18 8 C18 6 16 6 16 6 L16 11 L14 11 L14 3 C14 1 12 1 12 1 L12 11 L10 11 L10 1 C10 1 8 1 8 0 Z" fill="white" stroke="black" stroke-width="1.5"/></svg>') 4 0, pointer !important;
}
#game-container {
width: 100vw;
height: 100vh;
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#message {
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
font-size: 42px;
color: white;
background: rgba(0, 0, 0, 0.6);
padding: 20px 40px;
border-radius: 20px;
font-weight: bold;
text-align: center;
}
#score {
position: absolute;
top: 20px;
right: 30px;
font-size: 36px;
color: white;
background: rgba(0, 0, 0, 0.5);
padding: 15px 30px;
border-radius: 15px;
font-weight: bold;
}
#menu-button {
position: absolute;
top: 20px;
left: 30px;
font-size: 32px;
color: white;
background: rgba(0, 0, 0, 0.5);
padding: 15px 30px;
border-radius: 15px;
font-weight: bold;
cursor: pointer;
text-decoration: none;
display: inline-block;
transition: transform 0.2s;
}
#menu-button:hover {
transform: scale(1.1);
background: rgba(0, 0, 0, 0.7);
}
#color-display {
font-size: 72px;
font-weight: bold;
background: white;
padding: 40px 80px;
border-radius: 30px;
margin-bottom: 80px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
text-transform: uppercase;
}
#items-container {
display: flex;
gap: 40px;
flex-wrap: wrap;
justify-content: center;
max-width: 900px;
}
.color-item {
width: 150px;
height: 150px;
border-radius: 20px;
cursor: pointer;
transition: all 0.3s;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
display: flex;
align-items: center;
justify-content: center;
font-size: 60px;
}
.color-item:hover {
transform: scale(1.1);
}
.celebration {
position: absolute;
font-size: 60px;
animation: celebrate 1s ease forwards;
pointer-events: none;
}
@keyframes celebrate {
0% {
transform: scale(0) rotate(0deg);
opacity: 1;
}
100% {
transform: scale(1.5) rotate(360deg);
opacity: 0;
}
}
.rainbow {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 200px;
background: linear-gradient(to right,
red, orange, yellow, green, blue, indigo, violet);
opacity: 0;
transition: opacity 1s;
display: flex;
align-items: center;
justify-content: center;
font-size: 80px;
}
.rainbow.show {
opacity: 0.7;
}
</style>
</head>
<body>
<div id="game-container">
<a href="index.html" id="menu-button">๐ Menu</a>
<div id="message">Click the RED item!</div>
<div id="score">Score: 0</div>
<div id="color-display">RED</div>
<div id="items-container"></div>
<div id="rainbow" class="rainbow">๐ Rainbow! ๐</div>
</div>
<script>
// Montessori mode support
function isMontessoriMode() {
return localStorage.getItem('montessoriMode') === 'true';
}
if (isMontessoriMode()) {
document.body.classList.add('montessori');
}
const container = document.getElementById('game-container');
const itemsContainer = document.getElementById('items-container');
const message = document.getElementById('message');
const scoreDisplay = document.getElementById('score');
const colorDisplay = document.getElementById('color-display');
const rainbow = document.getElementById('rainbow');
const colors = [
{ name: 'RED', hex: '#FF6B6B', items: ['๐', '๐น', 'โค๏ธ', '๐'] },
{ name: 'BLUE', hex: '#4ECDC4', items: ['๐', '๐ฆ', '๐ณ', '๐ต'] },
{ name: 'YELLOW', hex: '#FFE66D', items: ['โญ', '๐', '๐ป', '๐'] },
{ name: 'GREEN', hex: '#95E1D3', items: ['๐', '๐ฟ', '๐ฒ', '๐'] },
{ name: 'PURPLE', hex: '#B388FF', items: ['๐', '๐', '๐ฆ', '๐ฎ'] },
{ name: 'ORANGE', hex: '#FFA500', items: ['๐', '๐งก', '๐ฅ', '๐'] },
{ name: 'PINK', hex: '#FFB3E6', items: ['๐ธ', '๐ฉท', '๐', '๐ฆฉ'] }
];
let score = 0;
let currentColor = null;
let messageTimeout;
let consecutiveCorrect = 0;
function showMessage(text, duration = 2000) {
message.textContent = text;
clearTimeout(messageTimeout);
if (duration > 0) {
messageTimeout = setTimeout(() => {
message.textContent = `Click the ${currentColor.name} item!`;
}, duration);
}
}
function playSuccess() {
try {
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const oscillator = audioContext.createOscillator();
const gainNode = audioContext.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioContext.destination);
// Montessori: consistent tone, no escalation
const volume = isMontessoriMode() ? 0.1 : 0.3;
const freq = isMontessoriMode() ? 500 : 500 + (consecutiveCorrect * 50);
oscillator.frequency.value = freq;
oscillator.type = 'sine';
gainNode.gain.setValueAtTime(volume, audioContext.currentTime);
gainNode.gain.exponentialRampToValueAtTime(0.01, audioContext.currentTime + 0.3);
oscillator.start(audioContext.currentTime);
oscillator.stop(audioContext.currentTime + 0.3);
} catch (e) {
// Audio not supported
}
}
function playWrong() {
if (isMontessoriMode()) return; // No harsh sounds in Montessori mode
try {
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const oscillator = audioContext.createOscillator();
const gainNode = audioContext.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioContext.destination);
oscillator.frequency.value = 200;
oscillator.type = 'sawtooth';
gainNode.gain.setValueAtTime(0.2, audioContext.currentTime);
gainNode.gain.exponentialRampToValueAtTime(0.01, audioContext.currentTime + 0.2);
oscillator.start(audioContext.currentTime);
oscillator.stop(audioContext.currentTime + 0.2);
} catch (e) {
// Audio not supported
}
}
function createCelebration(x, y) {
if (isMontessoriMode()) return; // No celebration bursts in Montessori mode
const emojis = ['โญ', 'โจ', '๐', 'โค๏ธ', '๐', '๐', '๐ซ'];
for (let i = 0; i < 10; i++) {
setTimeout(() => {
const cel = document.createElement('div');
cel.className = 'celebration';
cel.textContent = emojis[Math.floor(Math.random() * emojis.length)];
cel.style.left = (x + (Math.random() - 0.5) * 200) + 'px';
cel.style.top = (y + (Math.random() - 0.5) * 200) + 'px';
container.appendChild(cel);
setTimeout(() => {
cel.remove();
}, 1000);
}, i * 50);
}
}
function createNewRound() {
itemsContainer.innerHTML = '';
// Select target color
currentColor = colors[Math.floor(Math.random() * colors.length)];
colorDisplay.textContent = currentColor.name;
colorDisplay.style.color = currentColor.hex;
message.textContent = `Click the ${currentColor.name} item!`;
// Create a set of colors to show (including the target)
const displayColors = [currentColor];
const availableColors = colors.filter(c => c !== currentColor);
// Add 3-5 other random colors
const numOthers = 3 + Math.floor(Math.random() * 3);
for (let i = 0; i < numOthers && availableColors.length > 0; i++) {
const randomIndex = Math.floor(Math.random() * availableColors.length);
displayColors.push(availableColors[randomIndex]);
availableColors.splice(randomIndex, 1);
}
// Shuffle the display colors
displayColors.sort(() => Math.random() - 0.5);
// Create items for each color
displayColors.forEach(color => {
const item = document.createElement('div');
item.className = 'color-item';
item.style.backgroundColor = color.hex;
item.textContent = color.items[Math.floor(Math.random() * color.items.length)];
item.onclick = () => checkColor(color);
itemsContainer.appendChild(item);
});
}
function checkColor(selectedColor) {
if (selectedColor === currentColor) {
score += 10;
consecutiveCorrect++;
scoreDisplay.textContent = 'Score: ' + score;
showMessage('๐ Perfect! That\'s ' + currentColor.name + '!', 1500);
playSuccess();
createCelebration(window.innerWidth / 2, window.innerHeight / 2);
// Show rainbow every 5 correct answers
if (consecutiveCorrect % 5 === 0) {
rainbow.classList.add('show');
setTimeout(() => {
rainbow.classList.remove('show');
}, 2000);
}
setTimeout(() => {
createNewRound();
}, 1500);
} else {
consecutiveCorrect = 0;
showMessage('Try again! Look for ' + currentColor.name + '!', 2000);
playWrong();
}
}
// Start first round
createNewRound();
</script>
</body>
</html>