// Game state const gameState = { currentCard: 0, sum: 0, cardValues: [1, 2, 4, 8, 16, 32], }; // DOM elements const welcomeScreen = document.getElementById('welcomeScreen'); const cardScreen = document.getElementById('cardScreen'); const analysisScreen = document.getElementById('analysisScreen'); const resultScreen = document.getElementById('resultScreen'); const startBtn = document.getElementById('startBtn'); const yesBtn = document.getElementById('yesBtn'); const noBtn = document.getElementById('noBtn'); const restartBtn = document.getElementById('restartBtn'); const cardNumber = document.getElementById('cardNumber'); const cardGrid = document.getElementById('cardGrid'); const statusMessage = document.getElementById('statusMessage'); const progressBar = document.getElementById('progressBar'); const resultNumber = document.getElementById('resultNumber'); // Card values and their corresponding binary values const cardValues = [1, 2, 4, 8, 16, 32]; // Generate numbers for a specific card function generateCardNumbers(cardValue) { const numbers = []; for (let n = 1; n <= 63; n++) { if ((n & cardValue) !== 0) { numbers.push(n); } } return numbers; } // Display a card function displayCard(cardIndex) { const cardValue = cardValues[cardIndex]; const numbers = generateCardNumbers(cardValue); cardNumber.textContent = `Card ${cardIndex + 1} of 6`; cardGrid.innerHTML = ''; numbers.forEach((num) => { const numberDiv = document.createElement('div'); numberDiv.className = 'card-number'; numberDiv.textContent = num; cardGrid.appendChild(numberDiv); }); } // Handle Yes response function handleYes() { gameState.sum += gameState.cardValues[gameState.currentCard]; nextCard(); } // Handle No response function handleNo() { nextCard(); } // Move to the next card function nextCard() { gameState.currentCard++; if (gameState.currentCard < 6) { displayCard(gameState.currentCard); } else { // Move to analysis screen showAnalysisScreen(); } } // Show analysis screen with animations function showAnalysisScreen() { switchScreen(analysisScreen); animateAnalysis(); } // Animate the analysis screen function animateAnalysis() { const messages = [ 'Reading signals…', 'Matching pattern…', 'Locking onto your thought…', 'Decoding brainwaves…', 'Final verification…', ]; let messageIndex = 0; let progressValue = 0; // Cycle through messages const messageInterval = setInterval(() => { statusMessage.textContent = messages[messageIndex % messages.length]; messageIndex++; }, 400); // Simulate progress const progressInterval = setInterval(() => { progressValue += Math.random() * 15; if (progressValue > 100) progressValue = 100; progressBar.style.width = progressValue + '%'; if (progressValue >= 100) { clearInterval(progressInterval); } }, 200); // Reveal result after 2 seconds setTimeout(() => { clearInterval(messageInterval); clearInterval(progressInterval); revealResult(); }, 2000); } // Reveal the result function revealResult() { resultNumber.textContent = `Your number is ${gameState.sum}`; switchScreen(resultScreen); } // Switch between screens function switchScreen(targetScreen) { document.querySelectorAll('.screen').forEach((screen) => { screen.classList.remove('active'); }); targetScreen.classList.add('active'); } // Reset game function resetGame() { gameState.currentCard = 0; gameState.sum = 0; switchScreen(welcomeScreen); progressBar.style.width = '0%'; } // Event listeners startBtn.addEventListener('click', () => { gameState.currentCard = 0; gameState.sum = 0; displayCard(0); switchScreen(cardScreen); }); yesBtn.addEventListener('click', handleYes); noBtn.addEventListener('click', handleNo); restartBtn.addEventListener('click', resetGame); // Initialize window.addEventListener('load', () => { switchScreen(welcomeScreen); });