let currentLevel = null; let selectedWords = []; let cards = []; let matchedPairs = 0; let attempts = 0; let openedCards = []; let maxAttempts = 3; let recognition; function loadLevel(level) { document.getElementById('levelSelection').style.display = 'none'; currentLevel = level; selectedWords = WORDS[level]; initGame(selectedWords); } function openCustomLevelModal() { const modal = document.getElementById('customLevelModal'); const wordSelection = document.getElementById('wordSelection'); // Dynamické generování výběru slov wordSelection.innerHTML = Object.values(WORDS).flat().map(word => `` ).join(''); modal.style.display = 'block'; } function createCustomLevel() { const pairCount = document.getElementById('pairCount').value; const selectedCheckboxes = Array.from(document.querySelectorAll('#wordSelection input:checked')); selectedWords = selectedCheckboxes.map(cb => cb.value); if (selectedWords.length < pairCount) { alert('Vyberte dostatečný počet slov'); return; } // Náhodný výběr slov selectedWords = selectedWords.sort(() => 0.5 - Math.random()).slice(0, pairCount); document.getElementById('levelSelection').style.display = 'none'; document.getElementById('customLevelModal').style.display = 'none'; initGame(selectedWords); } function initGame(words) { const gameArea = document.getElementById('gameArea'); const cardsContainer = document.getElementById('cards'); gameArea.style.display = 'block'; cardsContainer.innerHTML = ''; matchedPairs = 0; attempts = 0; openedCards = []; // Zdvojení slov pro pexeso const gameWords = [...words, ...words].sort(() => 0.5 - Math.random()); gameWords.forEach((word, index) => { const card = document.createElement('div'); card.classList.add('card'); card.innerHTML = `
${word}
Výborne!
`; playSound('correct'); // Odebrání spárovaných karet document.querySelectorAll('.paired-cards').forEach(card => card.remove()); } else { attempts++; if (attempts >= maxAttempts) { gameOver(); } else { // Nesprávně vysloveno resultArea.innerHTML = `
Skúste znova (Pokus ${attempts}/${maxAttempts})
`; playSound('incorrect'); document.getElementById('startRecording').addEventListener('click', startSpeechRecognition); } } } function gameWon() { playSound('win'); alert('Gratulujeme! Vyhrali ste hru!'); resetGame(); } function gameOver() { playSound('lose'); alert('Presiahli ste maximálny počet pokusov. Hra skončila.'); resetGame(); } function resetGame() { document.getElementById('gameArea').style.display = 'none'; document.getElementById('levelSelection').style.display = 'block'; document.getElementById('result').innerHTML = ''; } function playSound(type) { // Implementace zvukových efektů const sounds = { 'flip': new Audio('./zvuky/effects/kopanie.mp3'), 'correct': new Audio('./zvuky/effects/spravne.mp3'), 'incorrect': new Audio('./zvuky/effects/zle.mp3'), 'win': new Audio('./zvuky/effects/vyhra.mp3'), 'lose': new Audio('./zvuky/effects/zle.mp3') }; if (sounds[type]) { sounds[type].play(); } } // Zavření modálního okna document.querySelector('.close').onclick = function() { document.getElementById('customLevelModal').style.display = 'none'; }