Memory Multi-Thèmes

Memory Animé

Joueur 1

0

Joueur 2

0

Configuration du jeu

1. Taille de la grille

2. Thème

${icon}
`; if (icon === '⭐') { card.addEventListener('click', function () { if (lockBoard || this.classList.contains('flipped')) return; this.classList.add('flipped'); setTimeout(() => { this.classList.add('matched'); // Bonus: the player who finds the star gets a point? // Or just remove it. Let's say it's just a freebie. scores[currentPlayer]++; updateUI(); // If it was the only card left, maybe game over? // But usually it's just a "found it" card. // We don't increment matchedPairs as it's not a pair. // But we need to check if game is over. checkGameOver(); }, 600); }); } else { card.addEventListener('click', flipCard); } grid.appendChild(card); }); } function flipCard() { if (lockBoard) return; if (this.classList.contains('flipped')) return; if (this.classList.contains('matched')) return; this.classList.add('flipped'); flippedCards.push(this); if (flippedCards.length === 2) { checkMatch(); } } function checkMatch() { lockBoard = true; const [card1, card2] = flippedCards; const isMatch = card1.dataset.icon === card2.dataset.icon; if (isMatch) { handleMatch(card1, card2); } else { unflipCards(card1, card2); } } function handleMatch(card1, card2) { scores[currentPlayer]++; matchedPairs++; updateUI(); card1.classList.add('matched'); card2.classList.add('matched'); flippedCards = []; lockBoard = false; checkGameOver(); } function checkGameOver() { const totalNeeded = totalPairs; const matchedCards = document.querySelectorAll('.card.matched').length; const totalCards = gridSize * gridSize; if (matchedCards === totalCards) { showWinner(); } } function unflipCards(card1, card2) { setTimeout(() => { card1.classList.remove('flipped'); card2.classList.remove('flipped'); switchPlayer(); flippedCards = []; lockBoard = false; }, 800); } function switchPlayer() { currentPlayer = currentPlayer === 0 ? 1 : 0; p1Area.classList.toggle('active-player'); p2Area.classList.toggle('active-player'); } function updateUI() { p1ScoreDisplay.innerText = scores[0]; p2ScoreDisplay.innerText = scores[1]; } function showWinner() { let msg = ""; if (scores[0] > scores[1]) { msg = "Le Joueur 1 Gagne ! 🏆"; } else if (scores[1] > scores[0]) { msg = "Le Joueur 2 Gagne ! 🏆"; } else { msg = "Égalité ! 🤝"; } winnerText.innerText = msg; modal.classList.remove('hidden'); } function resetGame() { scores = [0, 0]; currentPlayer = 0; matchedPairs = 0; flippedCards = []; lockBoard = false; p1Area.classList.add('active-player'); p2Area.classList.remove('active-player'); modal.classList.add('hidden'); updateUI(); createBoard(); } // Le jeu attend la sélection du thème au démarrage via la modale visible par défaut