Juego de Memoria - Gana Puntos
🎯 Juego de Memoria
',
'
',
// Agrega más banners aquí si quieres
];
let bannerIndex = 0;
const emojis = ['🍎','🍌','🍉','🍇','🍓','🍒'];
const deck = [...emojis, ...emojis].sort(() => 0.5 - Math.random());
deck.forEach((emoji, index) => {
const card = document.createElement('div');
card.classList.add('card');
card.dataset.value = emoji;
card.dataset.index = index;
card.textContent = emoji;
card.addEventListener('click', flipCard);
gameContainer.appendChild(card);
cards.push(card);
});
function flipCard() {
if (flippedCards.length >= 2 || this.classList.contains('flipped') || this.classList.contains('matched')) return;
this.classList.add('flipped');
flippedCards.push(this);
if (flippedCards.length === 2) {
setTimeout(checkMatch, 700);
}
}
function checkMatch() {
const [first, second] = flippedCards;
if (first.dataset.value === second.dataset.value) {
document.getElementById('match-sound').play();
first.classList.add('matched');
second.classList.add('matched');
points += 20;
localStorage.setItem('points', points);
pointsEl.textContent = points;
checkWin();
} else {
document.getElementById('error-sound').play();
first.classList.remove('flipped');
second.classList.remove('flipped');
attempts--;
attemptsEl.textContent = attempts;
if (attempts <= 0) showAdBanner();
}
flippedCards = [];
}
function checkWin() {
if (points >= pointsToWin) {
document.getElementById('success-sound').play();
claimBtn.style.display = 'inline-block';
claimBtn.onclick = () => window.location.href = redirectLink;
}
}
function showAdBanner() {
// Mostrar banner actual
adContainer.innerHTML = banners[bannerIndex];
adContainer.style.display = 'block';
// Avanzar al siguiente banner para la próxima vez
bannerIndex = (bannerIndex + 1) % banners.length;
// Reiniciar juego después de mostrar banner
setTimeout(resetGame, 1500);
}
function resetGame() {
attempts = 3;
attemptsEl.textContent = attempts;
cards.forEach(card => {
card.classList.remove('flipped', 'matched');
});
adContainer.style.display = 'none';
}