-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
729 lines (628 loc) · 31.9 KB
/
script.js
File metadata and controls
729 lines (628 loc) · 31.9 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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
const defaultConfig = {
game_title: "Memory Master",
welcome_message: "Challenge your friends in this epic memory battle!",
start_button_text: "Start Epic Game",
new_game_button_text: "Play Again",
developer_section_title: "About This Game"
};
const emojiSets = {
easy: ['🚀', '💡', '🎯'],
medium: ['🚀', '💡', '🎯', '⭐', '🔥', '💪'],
hard: ['🚀', '💡', '🎯', '⭐', '🔥', '💪', '🎨', '🎵', '🏆', '⚡'],
expert: ['🚀', '💡', '🎯', '⭐', '🔥', '💪', '🎨', '🎵', '🏆', '⚡', '🌟', '🎪', '🎭', '🎸', '🎲']
};
const matchingSets = {
animals: {
easy: ['🐶', '🐱', '🐭'],
medium: ['🐶', '🐱', '🐭', '🐹', '🐰', '🦊'],
hard: ['🐶', '🐱', '🐭', '🐹', '🐰', '🦊', '🐻', '🐼', '🐨', '🐯'],
expert: ['🐶', '🐱', '🐭', '🐹', '🐰', '🦊', '🐻', '🐼', '🐨', '🐯', '🦁', '🐸', '🐵', '🐧', '🦄']
},
food: {
easy: ['🍎', '🍌', '🍊'],
medium: ['🍎', '🍌', '🍊', '🍇', '🍓', '🥝'],
hard: ['🍎', '🍌', '🍊', '🍇', '🍓', '🥝', '🍑', '🍒', '🥭', '🍍'],
expert: ['🍎', '🍌', '🍊', '🍇', '🍓', '🥝', '🍑', '🍒', '🥭', '🍍', '🥥', '🍅', '🥑', '🌶️', '🥕']
},
sports: {
easy: ['⚽', '🏀', '🎾'],
medium: ['⚽', '🏀', '🎾', '🏈', '⚾', '🏐'],
hard: ['⚽', '🏀', '🎾', '🏈', '⚾', '🏐', '🏓', '🏸', '🥍', '🏒'],
expert: ['⚽', '🏀', '🎾', '🏈', '⚾', '🏐', '🏓', '🏸', '🥍', '🏒', '🏑', '🥊', '🤺', '🏹', '🎯']
},
nature: {
easy: ['🌸', '🌺', '🌻'],
medium: ['🌸', '🌺', '🌻', '🌷', '🌹', '🌼'],
hard: ['🌸', '🌺', '🌻', '🌷', '🌹', '🌼', '🌵', '🌲', '🌳', '🍀'],
expert: ['🌸', '🌺', '🌻', '🌷', '🌹', '🌼', '🌵', '🌲', '🌳', '🍀', '🌿', '🌾', '🌱', '🌴', '🎋']
},
vehicles: {
easy: ['🚗', '🚕', '🚙'],
medium: ['🚗', '🚕', '🚙', '🚌', '🚎', '🏎️'],
hard: ['🚗', '🚕', '🚙', '🚌', '🚎', '🏎️', '🚓', '🚑', '🚒', '🚐'],
expert: ['🚗', '🚕', '🚙', '🚌', '🚎', '🏎️', '🚓', '🚑', '🚒', '🚐', '🛻', '🚚', '🚛', '🚜', '🏍️']
},
space: {
easy: ['🌟', '🌙', '☀️'],
medium: ['🌟', '🌙', '☀️', '🪐', '🌍', '🌕'],
hard: ['🌟', '🌙', '☀️', '🪐', '🌍', '🌕', '🌑', '🌒', '🌓', '🌔'],
expert: ['🌟', '🌙', '☀️', '🪐', '🌍', '🌕', '🌑', '🌒', '🌓', '🌔', '🌖', '🌗', '🌘', '🌚', '🌝']
}
};
const questions = [
"What emoji best describes your morning?",
"What's a work skill you're proud of developing?",
"If you could have coffee with anyone, who would it be?",
"What's your favorite way to celebrate small wins?",
"What's one thing that always makes you smile at work?",
"If your job was a movie genre, what would it be?",
"What's the best piece of advice you've received recently?",
"What's your go-to productivity hack?",
"If you could learn any new skill instantly, what would it be?",
"What's something you're looking forward to this week?",
"What's your favorite way to unwind after work?",
"If you could master any hobby, what would it be?",
"What's the most interesting place you've visited?",
"What's your go-to comfort food?",
"If you could have dinner with any historical figure, who?",
"What's a skill you'd love to teach others?",
"What's your favorite season and why?",
"If you could live anywhere, where would it be?",
"What's the best compliment you've ever received?",
"What's your favorite way to start the weekend?"
];
const levels = [
{ name: "Warm Up", description: "Get ready to test your memory skills!" },
{ name: "Getting Started", description: "You're warming up nicely!" },
{ name: "Memory Builder", description: "Your brain is getting stronger!" },
{ name: "Focus Master", description: "Excellent concentration!" },
{ name: "Memory Champion", description: "You're becoming a pro!" },
{ name: "Brain Warrior", description: "Outstanding memory skills!" },
{ name: "Mind Master", description: "Your memory is incredible!" },
{ name: "Legend Status", description: "You're a memory legend!" }
];
let gameState = {
players: ['Player 1'],
currentPlayerIndex: 0,
playerScores: {},
cards: [],
flippedCards: [],
matchedPairs: 0,
totalPairs: 0,
moves: 0,
gameStarted: false,
currentQuestion: 0,
difficulty: 'medium',
level: 1,
startTime: null,
timer: null,
theme: 'mixed',
gameMode: 'normal',
speedTimer: null,
speedTimeLeft: 30,
mistakes: 0,
playerMistakes: {},
memoryPeekActive: false,
memoryPeekTimer: null,
powerUps: {
hints: 3,
shuffles: 2,
freezes: 1
},
freezeActive: false
};
// Player Management
function addPlayer() {
const input = document.getElementById('playerNameInput');
const name = input.value.trim();
if (!name) return;
if (gameState.players.length >= 6) {
showMessage("Maximum 6 players allowed!");
return;
}
if (gameState.players.includes(name)) {
showMessage("Player name already exists!");
return;
}
gameState.players.push(name);
gameState.playerScores[name] = 0;
input.value = '';
updatePlayersList();
}
function removePlayer(index) {
if (gameState.players.length <= 1) {
showMessage("At least one player required!");
return;
}
const playerName = gameState.players[index];
gameState.players.splice(index, 1);
delete gameState.playerScores[playerName];
if (gameState.currentPlayerIndex >= gameState.players.length) {
gameState.currentPlayerIndex = 0;
}
updatePlayersList();
}
function updatePlayersList() {
const container = document.getElementById('playersList');
container.innerHTML = '';
gameState.players.forEach((player, index) => {
const tag = document.createElement('div');
tag.className = 'player-tag';
tag.innerHTML = `${player} <button class="remove-player" onclick="removePlayer(${index})">×</button>`;
container.appendChild(tag);
});
}
function showMessage(text) {
const questionText = document.getElementById('questionText');
const originalText = questionText.textContent;
questionText.textContent = text;
setTimeout(() => {
questionText.textContent = originalText;
}, 2000);
}
function createGameBoard() {
const gameBoard = document.getElementById('gameBoard');
gameBoard.innerHTML = '';
// Get emojis based on theme
let emojis;
if (gameState.theme === 'mixed') {
emojis = emojiSets[gameState.difficulty];
} else {
emojis = matchingSets[gameState.theme][gameState.difficulty];
}
const cardEmojis = [...emojis, ...emojis];
gameState.totalPairs = emojis.length;
// Shuffle the cards
for (let i = cardEmojis.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[cardEmojis[i], cardEmojis[j]] = [cardEmojis[j], cardEmojis[i]];
}
gameState.cards = cardEmojis.map((emoji, index) => ({
id: index,
emoji: emoji,
flipped: false,
matched: false
}));
// Set board class based on difficulty
gameBoard.className = `game-board board-${gameState.difficulty}`;
gameState.cards.forEach((card, index) => {
const cardElement = document.createElement('div');
cardElement.className = 'card';
cardElement.dataset.cardId = index;
cardElement.innerHTML = `
<div class="card-back">❓</div>
<div class="card-front">${card.emoji}</div>
`;
cardElement.addEventListener('click', () => flipCard(index));
gameBoard.appendChild(cardElement);
});
// Memory mode: Show all cards for 3 seconds
if (gameState.gameMode === 'memory') {
showMemoryPeek();
}
}
function showMemoryPeek() {
gameState.memoryPeekActive = true;
const cards = document.querySelectorAll('.card');
cards.forEach(card => card.classList.add('flipped'));
gameState.memoryPeekTimer = setTimeout(() => {
cards.forEach(card => card.classList.remove('flipped'));
gameState.memoryPeekActive = false;
}, 3000);
}
function flipCard(cardId) {
if (!gameState.gameStarted || gameState.flippedCards.length >= 2 || gameState.memoryPeekActive) return;
const card = gameState.cards[cardId];
if (card.flipped || card.matched) return;
card.flipped = true;
gameState.flippedCards.push(cardId);
const cardElement = document.querySelector(`[data-card-id="${cardId}"]`);
cardElement.classList.add('flipped');
if (gameState.flippedCards.length === 2) {
gameState.moves++;
updateStats();
setTimeout(checkMatch, 1000);
}
}
function checkMatch() {
const [card1Id, card2Id] = gameState.flippedCards;
const card1 = gameState.cards[card1Id];
const card2 = gameState.cards[card2Id];
const currentPlayer = gameState.players[gameState.currentPlayerIndex];
if (card1.emoji === card2.emoji) {
// Match found
card1.matched = true;
card2.matched = true;
gameState.matchedPairs++;
const card1Element = document.querySelector(`[data-card-id="${card1Id}"]`);
const card2Element = document.querySelector(`[data-card-id="${card2Id}"]`);
card1Element.classList.add('matched');
card2Element.classList.add('matched');
// Award points based on game mode
let points = 10;
if (gameState.gameMode === 'speed') points = 15;
if (gameState.gameMode === 'memory') points = 20;
if (gameState.gameMode === 'challenge') points = 25;
gameState.playerScores[currentPlayer] += points;
// Show new question
showNewQuestion();
updateLeaderboard();
if (gameState.matchedPairs === gameState.totalPairs) {
setTimeout(showCelebration, 500);
}
} else {
// No match
card1.flipped = false;
card2.flipped = false;
const card1Element = document.querySelector(`[data-card-id="${card1Id}"]`);
const card2Element = document.querySelector(`[data-card-id="${card2Id}"]`);
card1Element.classList.remove('flipped');
card2Element.classList.remove('flipped');
// Handle mistakes in challenge mode
if (gameState.gameMode === 'challenge') {
gameState.playerMistakes[currentPlayer] = (gameState.playerMistakes[currentPlayer] || 0) + 1;
gameState.mistakes++;
updateStats();
if (gameState.playerMistakes[currentPlayer] >= 1) {
showMessage(`${currentPlayer} made a mistake! Turn skipped.`);
}
}
// Switch to next player
gameState.currentPlayerIndex = (gameState.currentPlayerIndex + 1) % gameState.players.length;
updateCurrentPlayer();
}
gameState.flippedCards = [];
updateStats();
}
function updateCurrentPlayer() {
const currentPlayerName = gameState.players[gameState.currentPlayerIndex];
document.getElementById('currentPlayerName').textContent = currentPlayerName;
}
function updateLeaderboard() {
const container = document.getElementById('playerScores');
const sortedPlayers = Object.entries(gameState.playerScores)
.sort(([,a], [,b]) => b - a);
container.innerHTML = '';
sortedPlayers.forEach(([player, score], index) => {
const scoreElement = document.createElement('div');
scoreElement.className = 'player-score';
const medal = index === 0 ? '🥇' : index === 1 ? '🥈' : index === 2 ? '🥉' : '🏅';
scoreElement.innerHTML = `<span>${medal} ${player}</span><span>${score} pts</span>`;
container.appendChild(scoreElement);
});
}
function startTimer() {
gameState.startTime = Date.now();
gameState.timer = setInterval(() => {
const elapsed = Math.floor((Date.now() - gameState.startTime) / 1000);
document.getElementById('timeElapsed').textContent = elapsed;
}, 1000);
}
function stopTimer() {
if (gameState.timer) {
clearInterval(gameState.timer);
gameState.timer = null;
}
}
function startSpeedTimer() {
if (gameState.gameMode !== 'speed') return;
gameState.speedTimeLeft = 30;
document.getElementById('speedTimeLeft').textContent = gameState.speedTimeLeft;
document.getElementById('speedTimer').classList.remove('hidden');
gameState.speedTimer = setInterval(() => {
gameState.speedTimeLeft--;
document.getElementById('speedTimeLeft').textContent = gameState.speedTimeLeft;
if (gameState.speedTimeLeft <= 0) {
clearInterval(gameState.speedTimer);
// Auto-switch player when time runs out
gameState.currentPlayerIndex = (gameState.currentPlayerIndex + 1) % gameState.players.length;
updateCurrentPlayer();
showMessage(`Time's up! Next player's turn.`);
startSpeedTimer(); // Start timer for next player
}
}, 1000);
}
function stopSpeedTimer() {
if (gameState.speedTimer) {
clearInterval(gameState.speedTimer);
gameState.speedTimer = null;
}
}
function showNewQuestion() {
const questionText = document.getElementById('questionText');
questionText.textContent = questions[gameState.currentQuestion % questions.length];
gameState.currentQuestion++;
}
function updateStats() {
document.getElementById('moves').textContent = gameState.moves;
document.getElementById('matches').textContent = gameState.matchedPairs;
document.getElementById('currentLevel').textContent = gameState.level;
// Show/hide mode-specific stats
if (gameState.gameMode === 'challenge') {
document.getElementById('mistakeCounter').classList.remove('hidden');
document.getElementById('mistakes').textContent = gameState.mistakes;
} else {
document.getElementById('mistakeCounter').classList.add('hidden');
}
}
function updateLevelInfo() {
const levelData = levels[(gameState.level - 1) % levels.length];
document.getElementById('levelTitle').textContent = `Level ${gameState.level} - ${levelData.name}`;
document.getElementById('levelDescription').textContent = levelData.description;
}
function startGame() {
gameState.difficulty = document.getElementById('difficultySelect').value;
gameState.theme = document.getElementById('themeSelect').value;
gameState.gameMode = document.getElementById('gameModeSelect').value;
gameState.gameStarted = true;
gameState.matchedPairs = 0;
gameState.moves = 0;
gameState.mistakes = 0;
gameState.flippedCards = [];
gameState.currentPlayerIndex = 0;
// Initialize player scores and mistakes
gameState.players.forEach(player => {
if (!(player in gameState.playerScores)) {
gameState.playerScores[player] = 0;
}
gameState.playerMistakes[player] = 0;
});
createGameBoard();
updateStats();
updateLevelInfo();
updateCurrentPlayer();
updateLeaderboard();
showNewQuestion();
startTimer();
// Start mode-specific timers
if (gameState.gameMode === 'speed') {
startSpeedTimer();
}
// Show/hide UI elements
document.getElementById('playerSetup').classList.add('hidden');
document.getElementById('levelInfo').classList.remove('hidden');
document.getElementById('currentPlayerDisplay').classList.remove('hidden');
document.getElementById('gameStats').classList.remove('hidden');
document.getElementById('leaderboard').classList.remove('hidden');
document.getElementById('startBtn').classList.add('hidden');
document.getElementById('newGameBtn').classList.remove('hidden');
document.getElementById('celebration').classList.add('hidden');
}
function nextLevel() {
gameState.level++;
gameState.matchedPairs = 0;
gameState.moves = 0;
gameState.mistakes = 0;
gameState.flippedCards = [];
gameState.currentPlayerIndex = 0;
// Reset player mistakes
gameState.players.forEach(player => {
gameState.playerMistakes[player] = 0;
});
createGameBoard();
updateStats();
updateLevelInfo();
updateCurrentPlayer();
showNewQuestion();
startTimer();
// Restart mode-specific timers
if (gameState.gameMode === 'speed') {
startSpeedTimer();
}
document.getElementById('celebration').classList.add('hidden');
document.getElementById('nextLevelBtn').classList.add('hidden');
}
function newGame() {
stopTimer();
stopSpeedTimer();
if (gameState.memoryPeekTimer) {
clearTimeout(gameState.memoryPeekTimer);
}
gameState = {
players: gameState.players,
currentPlayerIndex: 0,
playerScores: {},
cards: [],
flippedCards: [],
matchedPairs: 0,
totalPairs: 0,
moves: 0,
gameStarted: false,
currentQuestion: 0,
difficulty: 'medium',
level: 1,
startTime: null,
timer: null,
theme: 'mixed',
gameMode: 'normal',
speedTimer: null,
speedTimeLeft: 30,
mistakes: 0,
playerMistakes: {},
memoryPeekActive: false,
memoryPeekTimer: null
};
// Reset player scores
gameState.players.forEach(player => {
gameState.playerScores[player] = 0;
});
// Show/hide UI elements
document.getElementById('playerSetup').classList.remove('hidden');
document.getElementById('levelInfo').classList.add('hidden');
document.getElementById('currentPlayerDisplay').classList.add('hidden');
document.getElementById('gameStats').classList.add('hidden');
document.getElementById('leaderboard').classList.add('hidden');
document.getElementById('startBtn').classList.remove('hidden');
document.getElementById('newGameBtn').classList.add('hidden');
document.getElementById('nextLevelBtn').classList.add('hidden');
document.getElementById('celebration').classList.add('hidden');
document.getElementById('speedTimer').classList.add('hidden');
document.getElementById('mistakeCounter').classList.add('hidden');
document.getElementById('gameBoard').innerHTML = '';
document.getElementById('questionText').textContent = 'Set up your players and start the game to discover conversation starters!';
document.getElementById('timeElapsed').textContent = '0';
document.getElementById('speedTimeLeft').textContent = '30';
document.getElementById('mistakes').textContent = '0';
}
function showCelebration() {
stopTimer();
stopSpeedTimer();
// Update footer stats
incrementGamesPlayed();
const topScore = Math.max(...Object.values(gameState.playerScores));
updateBestScore(topScore);
const levelData = levels[(gameState.level - 1) % levels.length];
const modeBonus = gameState.gameMode === 'speed' ? ' (Speed Bonus!)' :
gameState.gameMode === 'memory' ? ' (Memory Master!)' :
gameState.gameMode === 'challenge' ? ' (Challenge Conquered!)' : '';
document.getElementById('celebrationText').textContent =
`${levelData.description}${modeBonus} Ready for Level ${gameState.level + 1}?`;
document.getElementById('celebration').classList.remove('hidden');
document.getElementById('nextLevelBtn').classList.remove('hidden');
}
function render(config) {
document.getElementById('gameTitle').textContent = config.game_title || defaultConfig.game_title;
document.getElementById('welcomeMessage').textContent = config.welcome_message || defaultConfig.welcome_message;
document.getElementById('startBtn').textContent = config.start_button_text || defaultConfig.start_button_text;
document.getElementById('newGameBtn').textContent = config.new_game_button_text || defaultConfig.new_game_button_text;
document.getElementById('developerSectionTitle').textContent = config.developer_section_title || defaultConfig.developer_section_title;
}
// Theme Management
function toggleTheme() {
const body = document.body;
const themeBtn = document.getElementById('themeBtn');
const isDark = body.classList.contains('dark-theme');
if (isDark) {
body.classList.remove('dark-theme');
themeBtn.textContent = '🌙';
themeBtn.title = 'Switch to Dark Theme';
localStorage.setItem('theme', 'light');
} else {
body.classList.add('dark-theme');
themeBtn.textContent = '☀️';
themeBtn.title = 'Switch to Light Theme';
localStorage.setItem('theme', 'dark');
}
}
function loadTheme() {
const savedTheme = localStorage.getItem('theme');
const themeBtn = document.getElementById('themeBtn');
if (savedTheme === 'dark') {
document.body.classList.add('dark-theme');
themeBtn.textContent = '☀️';
themeBtn.title = 'Switch to Light Theme';
} else {
themeBtn.textContent = '🌙';
themeBtn.title = 'Switch to Dark Theme';
}
}
// Event listeners
document.getElementById('startBtn').addEventListener('click', startGame);
document.getElementById('newGameBtn').addEventListener('click', newGame);
document.getElementById('nextLevelBtn').addEventListener('click', nextLevel);
document.getElementById('addPlayerBtn').addEventListener('click', addPlayer);
document.getElementById('themeBtn').addEventListener('click', toggleTheme);
document.getElementById('logoSection').addEventListener('click', () => {
// Add reload animation
const logoIcon = document.querySelector('.logo-icon');
logoIcon.style.animation = 'none';
logoIcon.offsetHeight; // Trigger reflow
logoIcon.style.animation = 'bounce 0.6s ease-in-out';
// Reload page after animation
setTimeout(() => {
window.location.reload();
}, 600);
});
document.getElementById('developerBtn').addEventListener('click', () => {
document.getElementById('developerModal').classList.remove('hidden');
});
document.getElementById('closeModalBtn').addEventListener('click', () => {
document.getElementById('developerModal').classList.add('hidden');
});
document.getElementById('developerModal').addEventListener('click', (e) => {
if (e.target.id === 'developerModal') {
document.getElementById('developerModal').classList.add('hidden');
}
});
// Enter key support for adding players
document.getElementById('playerNameInput').addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
addPlayer();
}
});
// Initialize player scores
gameState.players.forEach(player => {
gameState.playerScores[player] = 0;
});
// Footer stats management
let footerStats = {
gamesPlayed: parseInt(localStorage.getItem('memoryMasterGamesPlayed') || '0'),
bestScore: parseInt(localStorage.getItem('memoryMasterBestScore') || '0')
};
function updateFooterStats() {
document.getElementById('footerGamesPlayed').textContent = footerStats.gamesPlayed;
document.getElementById('footerBestScore').textContent = footerStats.bestScore;
}
function incrementGamesPlayed() {
footerStats.gamesPlayed++;
localStorage.setItem('memoryMasterGamesPlayed', footerStats.gamesPlayed.toString());
updateFooterStats();
}
function updateBestScore(score) {
if (score > footerStats.bestScore) {
footerStats.bestScore = score;
localStorage.setItem('memoryMasterBestScore', footerStats.bestScore.toString());
updateFooterStats();
}
}
// Create floating particles for intro animation
function createParticles() {
const particlesContainer = document.getElementById('introParticles');
if (!particlesContainer) return;
const particleCount = 50;
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
// Random starting position
particle.style.left = Math.random() * 100 + '%';
particle.style.animationDelay = Math.random() * 6 + 's';
particle.style.animationDuration = (Math.random() * 3 + 4) + 's';
// Random size variation
const size = Math.random() * 3 + 2;
particle.style.width = size + 'px';
particle.style.height = size + 'px';
// Random opacity
particle.style.opacity = Math.random() * 0.5 + 0.3;
particlesContainer.appendChild(particle);
}
}
// Initialize particles when page loads
document.addEventListener('DOMContentLoaded', () => {
createParticles();
});
// Initialize SDK
if (window.elementSdk) {
window.elementSdk.init({
defaultConfig,
render,
mapToCapabilities: (config) => ({
recolorables: [],
borderables: [],
fontEditable: undefined,
fontSizeable: undefined
}),
mapToEditPanelValues: (config) => new Map([
["game_title", config.game_title || defaultConfig.game_title],
["welcome_message", config.welcome_message || defaultConfig.welcome_message],
["start_button_text", config.start_button_text || defaultConfig.start_button_text],
["new_game_button_text", config.new_game_button_text || defaultConfig.new_game_button_text],
["developer_section_title", config.developer_section_title || defaultConfig.developer_section_title]
])
});
}
// Initial render
render(defaultConfig);
updatePlayersList();
loadTheme();
updateFooterStats();
(function(){function c(){var b=a.contentDocument||a.contentWindow.document;if(b){var d=b.createElement('script');d.innerHTML="window.__CF$cv$params={r:'99119607802d25b1',t:'MTc2MDg5MDY1MS4wMDAwMDA='};var a=document.createElement('script');a.nonce='';a.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js';document.getElementsByTagName('head')[0].appendChild(a);";b.getElementsByTagName('head')[0].appendChild(d)}}if(document.body){var a=document.createElement('iframe');a.height=1;a.width=1;a.style.position='absolute';a.style.top=0;a.style.left=0;a.style.border='none';a.style.visibility='hidden';document.body.appendChild(a);if('loading'!==document.readyState)c();else if(window.addEventListener)document.addEventListener('DOMContentLoaded',c);else{var e=document.onreadystatechange||function(){};document.onreadystatechange=function(b){e(b);'loading'!==document.readyState&&(document.onreadystatechange=e,c())}}}})();