Spaces:
Running
Running
redo this code as i am unable to start the game and make it so that aster the host has votes it will show whether the answer was right or wrong and if wrong the point goes to whoall - Initial Deployment
f21c265 verified Download index.html from Whynot7724/kivda: direct link, hf CLI and curl.
- Browser
- Download file 46 kB
-
https://huggingface.co/spaces/Whynot7724/kivda/resolve/main/index.html
- Command line
-
hf download hf://spaces/Whynot7724/kivda/index.html
-
curl -L -o index.html https://huggingface.co/spaces/Whynot7724/kivda/resolve/main/index.html
46 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Truth Detector - Multiplayer Party Game</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/js/all.min.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/party-js@latest/bundle/party.min.js"></script> | |
| <style> | |
| .fade-in { | |
| animation: fadeIn 0.5s; | |
| } | |
| @keyframes fadeIn { | |
| from { opacity: 0; } | |
| to { opacity: 1; } | |
| } | |
| .role-reveal { | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| color: white; | |
| border-radius: 1rem; | |
| padding: 2rem; | |
| box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); | |
| } | |
| .role-truth { | |
| background: linear-gradient(135deg, #48bb78 0%, #2f855a 100%); | |
| } | |
| .role-liar { | |
| background: linear-gradient(135deg, #f56565 0%, #c53030 100%); | |
| } | |
| .role-player { | |
| background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%); | |
| } | |
| .question-card { | |
| background: white; | |
| border-radius: 1rem; | |
| box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); | |
| } | |
| .option:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); | |
| } | |
| .correct-answer { | |
| animation: pulse 2s infinite; | |
| border: 3px solid #48bb78; | |
| } | |
| @keyframes pulse { | |
| 0% { box-shadow: 0 0 0 0 rgba(72, 187, 120, 0.7); } | |
| 70% { box-shadow: 0 0 0 10px rgba(72, 187, 120, 0); } | |
| 100% { box-shadow: 0 0 0 0 rgba(72, 187, 120, 0); } | |
| } | |
| .wrong-answer { | |
| border: 3px solid #f56565; | |
| } | |
| .progress-bar { | |
| height: 8px; | |
| background-color: #e2e8f0; | |
| border-radius: 4px; | |
| overflow: hidden; | |
| } | |
| .progress-fill { | |
| height: 100%; | |
| background-color: #4299e1; | |
| transition: width 1s linear; | |
| } | |
| .emoji-reaction { | |
| font-size: 2rem; | |
| cursor: pointer; | |
| transition: transform 0.2s; | |
| } | |
| .emoji-reaction:hover { | |
| transform: scale(1.2); | |
| } | |
| .dark-mode { | |
| background-color: #1a202c; | |
| color: #e2e8f0; | |
| } | |
| .dark-mode .bg-white { | |
| background-color: #2d3748; | |
| } | |
| .dark-mode .text-gray-800 { | |
| color: #e2e8f0; | |
| } | |
| .dark-mode .text-gray-600 { | |
| color: #a0aec0; | |
| } | |
| .cyberpunk-mode { | |
| background-color: #0f0f1b; | |
| color: #00ffff; | |
| font-family: 'Courier New', monospace; | |
| } | |
| .cyberpunk-mode .bg-white { | |
| background-color: #1a1a2e; | |
| border: 1px solid #00ffff; | |
| } | |
| .cyberpunk-mode .text-gray-800 { | |
| color: #00ffff; | |
| } | |
| .cyberpunk-mode .text-gray-600 { | |
| color: #00ffcc; | |
| } | |
| .cyberpunk-mode button { | |
| border: 1px solid #00ffff; | |
| background-color: #1a1a2e; | |
| color: #00ffff; | |
| } | |
| .cyberpunk-mode .question-card { | |
| border: 2px solid #00ffff; | |
| box-shadow: 0 0 10px #00ffff; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-100 min-h-screen font-sans"> | |
| <!-- Main App Container --> | |
| <div class="container mx-auto px-4 py-8 max-w-4xl"> | |
| <!-- Header --> | |
| <header class="text-center mb-8"> | |
| <h1 class="text-4xl font-bold text-purple-800 mb-2">Truth Detector</h1> | |
| <p class="text-gray-600">A multiplayer hybrid party game of deception and deduction</p> | |
| </header> | |
| <!-- Main Game Area --> | |
| <div id="app" class="bg-white rounded-xl shadow-lg overflow-hidden fade-in"> | |
| <!-- Home Screen --> | |
| <div id="home-screen" class="p-8 text-center"> | |
| <div class="mb-8"> | |
| <img src="https://cdn-icons-png.flaticon.com/512/3132/3132693.png" alt="Truth Detector Logo" class="w-32 h-32 mx-auto mb-4"> | |
| <h2 class="text-2xl font-semibold text-gray-800 mb-4">Welcome to Truth Detector!</h2> | |
| <p class="text-gray-600 mb-6">Create or join a game room to start playing with friends.</p> | |
| </div> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-4"> | |
| <button id="create-room-btn" class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-3 px-6 rounded-lg transition duration-300 flex items-center justify-center"> | |
| <i class="fas fa-plus-circle mr-2"></i> Create Room | |
| </button> | |
| <button id="join-room-btn" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-3 px-6 rounded-lg transition duration-300 flex items-center justify-center"> | |
| <i class="fas fa-door-open mr-2"></i> Join Room | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Create Room Screen --> | |
| <div id="create-room-screen" class="hidden p-8"> | |
| <h2 class="text-2xl font-semibold text-gray-800 mb-6">Create a New Game Room</h2> | |
| <div class="mb-6"> | |
| <label class="block text-gray-700 font-medium mb-2" for="player-name">Your Name</label> | |
| <input type="text" id="host-name" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-600" placeholder="Enter your name"> | |
| </div> | |
| <div class="mb-6"> | |
| <label class="block text-gray-700 font-medium mb-2">Question Set</label> | |
| <div class="space-y-2"> | |
| <div class="flex items-center"> | |
| <input type="radio" id="default-questions" name="question-set" value="default" checked class="mr-2"> | |
| <label for="default-questions">Use Default Questions</label> | |
| </div> | |
| <div class="flex items-center"> | |
| <input type="radio" id="custom-questions" name="question-set" value="custom" class="mr-2"> | |
| <label for="custom-questions">Upload Custom Questions (CSV)</label> | |
| </div> | |
| </div> | |
| <div id="custom-upload-container" class="mt-4 hidden"> | |
| <input type="file" id="custom-questions-file" accept=".csv" class="hidden"> | |
| <label for="custom-questions-file" class="cursor-pointer bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-2 px-4 rounded-lg inline-flex items-center"> | |
| <i class="fas fa-file-upload mr-2"></i> Choose CSV File | |
| </label> | |
| <span id="file-name" class="ml-2 text-gray-600">No file selected</span> | |
| <p class="text-sm text-gray-500 mt-1">CSV format: Question | Option A | Option B | Option C | Option D | Correct Answer</p> | |
| </div> | |
| </div> | |
| <div class="flex space-x-4"> | |
| <button id="start-room-btn" class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-2 px-6 rounded-lg transition duration-300"> | |
| Start Game | |
| </button> | |
| <button id="back-to-home-from-create" class="bg-gray-200 hover:bg-gray-300 text-gray-800 font-bold py-2 px-6 rounded-lg transition duration-300"> | |
| Cancel | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Join Room Screen --> | |
| <div id="join-room-screen" class="hidden p-8"> | |
| <h2 class="text-2xl font-semibold text-gray-800 mb-6">Join a Game Room</h2> | |
| <div class="mb-6"> | |
| <label class="block text-gray-700 font-medium mb-2" for="player-name">Your Name</label> | |
| <input type="text" id="player-name" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-600" placeholder="Enter your name"> | |
| </div> | |
| <div class="mb-6"> | |
| <label class="block text-gray-700 font-medium mb-2" for="room-code">Room Code</label> | |
| <input type="text" id="room-code" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-600" placeholder="Enter 6-digit room code"> | |
| </div> | |
| <div class="flex space-x-4"> | |
| <button id="join-room-submit-btn" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-6 rounded-lg transition duration-300"> | |
| Join Room | |
| </button> | |
| <button id="back-to-home-from-join" class="bg-gray-200 hover:bg-gray-300 text-gray-800 font-bold py-2 px-6 rounded-lg transition duration-300"> | |
| Cancel | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Waiting Room Screen --> | |
| <div id="waiting-room-screen" class="hidden p-8"> | |
| <div class="flex justify-between items-center mb-6"> | |
| <h2 class="text-2xl font-semibold text-gray-800">Waiting for Players</h2> | |
| <div class="bg-purple-100 text-purple-800 px-4 py-2 rounded-lg"> | |
| Room Code: <span id="display-room-code" class="font-bold">123456</span> | |
| </div> | |
| </div> | |
| <div class="mb-8"> | |
| <div class="flex justify-between items-center mb-2"> | |
| <span class="text-gray-700 font-medium">Players Joined (<span id="player-count">1</span>)</span> | |
| <button id="copy-room-code" class="text-purple-600 hover:text-purple-800 text-sm flex items-center"> | |
| <i class="fas fa-copy mr-1"></i> Copy Code | |
| </button> | |
| </div> | |
| <div id="player-list" class="bg-gray-50 rounded-lg p-4 min-h-32"> | |
| <div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-2"> | |
| <!-- Players will be added here dynamically --> | |
| </div> | |
| </div> | |
| </div> | |
| <div id="host-controls" class="hidden"> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 font-medium mb-2">Game Settings</label> | |
| <div class="flex items-center space-x-4"> | |
| <div class="flex items-center"> | |
| <input type="number" id="rounds-count" min="1" max="20" value="10" class="w-16 px-2 py-1 border border-gray-300 rounded-lg"> | |
| <label for="rounds-count" class="ml-2 text-gray-700">Rounds</label> | |
| </div> | |
| <div class="flex items-center"> | |
| <select id="timer-duration" class="px-2 py-1 border border-gray-300 rounded-lg"> | |
| <option value="120">2 Minutes</option> | |
| <option value="300" selected>5 Minutes</option> | |
| <option value="600">10 Minutes</option> | |
| </select> | |
| </div> | |
| </div> | |
| </div> | |
| <button id="start-game-btn" class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-2 px-6 rounded-lg transition duration-300 w-full"> | |
| Start Game | |
| </button> | |
| </div> | |
| <div id="player-waiting" class="text-center py-8"> | |
| <div class="animate-pulse flex flex-col items-center"> | |
| <i class="fas fa-users text-4xl text-purple-300 mb-4"></i> | |
| <p class="text-gray-600">Waiting for host to start the game...</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Role Reveal Screen --> | |
| <div id="role-reveal-screen" class="hidden p-8"> | |
| <div class="role-reveal text-center max-w-md mx-auto"> | |
| <h2 class="text-2xl font-bold mb-4">Your Role</h2> | |
| <div id="role-icon" class="text-6xl mb-4"> | |
| <i class="fas fa-user"></i> | |
| </div> | |
| <h3 id="role-title" class="text-xl font-semibold mb-2">Player</h3> | |
| <p id="role-description" class="mb-6">Answer questions normally and try to detect who's lying!</p> | |
| <button id="continue-to-game-btn" class="bg-white text-purple-800 font-bold py-2 px-6 rounded-lg transition duration-300"> | |
| Continue to Game | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Game Screen --> | |
| <div id="game-screen" class="hidden p-4 md:p-8"> | |
| <div class="flex justify-between items-center mb-6"> | |
| <div class="bg-purple-100 text-purple-800 px-3 py-1 rounded-lg text-sm"> | |
| Round <span id="current-round">1</span>/<span id="total-rounds">10</span> | |
| </div> | |
| <div id="player-role-indicator" class="bg-gray-200 text-gray-800 px-3 py-1 rounded-lg text-sm hidden"> | |
| <i class="fas fa-user-secret mr-1"></i> <span id="player-role-text">Player</span> | |
| </div> | |
| </div> | |
| <div id="question-container" class="question-card p-6 mb-6"> | |
| <div class="flex justify-between items-start mb-4"> | |
| <h3 class="text-lg font-semibold text-gray-700">Question:</h3> | |
| <div id="timer" class="bg-gray-100 text-gray-800 px-3 py-1 rounded-full text-sm font-mono hidden"> | |
| 00:30 | |
| </div> | |
| </div> | |
| <h2 id="question-text" class="text-xl font-bold text-gray-800 mb-6">Loading question...</h2> | |
| <div id="options-container" class="grid grid-cols-1 md:grid-cols-2 gap-3"> | |
| <div class="option bg-gray-50 hover:bg-gray-100 p-4 rounded-lg cursor-pointer transition duration-300" data-option="A"> | |
| <div class="flex items-center"> | |
| <div class="w-8 h-8 bg-purple-100 text-purple-800 rounded-full flex items-center justify-center font-bold mr-3">A</div> | |
| <span id="option-a-text">Option A</span> | |
| </div> | |
| </div> | |
| <div class="option bg-gray-50 hover:bg-gray-100 p-4 rounded-lg cursor-pointer transition duration-300" data-option="B"> | |
| <div class="flex items-center"> | |
| <div class="w-8 h-8 bg-purple-100 text-purple-800 rounded-full flex items-center justify-center font-bold mr-3">B</div> | |
| <span id="option-b-text">Option B</span> | |
| </div> | |
| </div> | |
| <div class="option bg-gray-50 hover:bg-gray-100 p-4 rounded-lg cursor-pointer transition duration-300" data-option="C"> | |
| <div class="flex items-center"> | |
| <div class="w-8 h-8 bg-purple-100 text-purple-800 rounded-full flex items-center justify-center font-bold mr-3">C</div> | |
| <span id="option-c-text">Option C</span> | |
| </div> | |
| </div> | |
| <div class="option bg-gray-50 hover:bg-gray-100 p-4 rounded-lg cursor-pointer transition duration-300" data-option="D"> | |
| <div class="flex items-center"> | |
| <div class="w-8 h-8 bg-purple-100 text-purple-800 rounded-full flex items-center justify-center font-bold mr-3">D</div> | |
| <span id="option-d-text">Option D</span> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div id="discussion-phase" class="text-center py-8"> | |
| <div class="max-w-md mx-auto"> | |
| <i class="fas fa-comments text-4xl text-purple-300 mb-4"></i> | |
| <h3 class="text-xl font-semibold text-gray-800 mb-2">Discussion Phase</h3> | |
| <p class="text-gray-600 mb-4">Three players will try to deceive you while one will convince you of the truth!</p> | |
| <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-4 text-left"> | |
| <p class="text-sm text-yellow-700"><i class="fas fa-exclamation-triangle mr-2"></i> Only the host can select the answer. Discuss until time runs out!</p> | |
| </div> | |
| <div class="grid grid-cols-3 gap-2 mb-4"> | |
| <div class="bg-red-100 text-red-800 p-2 rounded-lg text-sm">3 Deceivers</div> | |
| <div class="bg-green-100 text-green-800 p-2 rounded-lg text-sm">1 Truth Convincer</div> | |
| <div class="bg-blue-100 text-blue-800 p-2 rounded-lg text-sm">1 Host</div> | |
| </div> | |
| </div> | |
| </div> | |
| <div id="host-controls-game" class="hidden mt-6"> | |
| <button id="next-question-btn" class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-2 px-6 rounded-lg transition duration-300 w-full"> | |
| Next Question | |
| </button> | |
| </div> | |
| <div id="answer-reveal" class="hidden mt-6 p-6 bg-gray-50 rounded-lg"> | |
| <h3 class="text-lg font-semibold text-gray-800 mb-4">Round Results</h3> | |
| <div id="correctness-display" class="text-xl font-bold mb-2"></div> | |
| <div id="winner-display" class="text-lg mb-4"></div> | |
| <div id="points-display" class="text-md mb-4"></div> | |
| <h4 class="font-semibold text-gray-700 mb-2">Correct Answer:</h4> | |
| <div id="correct-answer-display" class="text-xl font-bold text-purple-800 mb-4"></div> | |
| <p id="answer-explanation" class="text-gray-600">Explanation not available</p> | |
| </div> | |
| </div> | |
| <!-- Game Over Screen --> | |
| <div id="game-over-screen" class="hidden p-8 text-center"> | |
| <h2 class="text-3xl font-bold text-purple-800 mb-4">Game Over!</h2> | |
| <p class="text-gray-600 mb-8">Thanks for playing Truth Detector!</p> | |
| <div class="max-w-md mx-auto"> | |
| <button id="play-again-btn" class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-2 px-6 rounded-lg transition duration-300 mb-4 w-full"> | |
| Play Again | |
| </button> | |
| <button id="return-home-btn" class="bg-gray-200 hover:bg-gray-300 text-gray-800 font-bold py-2 px-6 rounded-lg transition duration-300 w-full"> | |
| Return to Home | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Footer --> | |
| <footer class="text-center mt-12 text-gray-500 text-sm"> | |
| <p>Truth Detector - A multiplayer party game of deception and deduction</p> | |
| </footer> | |
| </div> | |
| <script> | |
| // Game state | |
| const gameState = { | |
| currentScreen: 'home', | |
| isHost: false, | |
| roomCode: '', | |
| playerName: '', | |
| playerRole: 'player', // 'player', 'truth-convincer', 'deceiver' | |
| currentRound: 0, | |
| totalRounds: 10, | |
| players: [], | |
| questions: [], | |
| currentQuestion: null, | |
| selectedAnswer: null, | |
| correctAnswer: null, | |
| timerInterval: null, | |
| timerDuration: 300, // 5 minutes default | |
| roundResults: [], // To track who won each round | |
| playerScores: {} // To track player scores | |
| }; | |
| // Philosophical/Ethical questions | |
| const defaultQuestions = [ | |
| { | |
| question: "In a situation where lying saves a life, is it morally acceptable?", | |
| options: { | |
| A: "Yes, saving lives justifies lying", | |
| B: "No, truth must always be preserved", | |
| C: "Only if no one is harmed by the lie", | |
| D: "Depends on cultural context" | |
| }, | |
| correctAnswer: "B", | |
| explanation: "Philosophers like Kant argue truth-telling is a universal moral duty regardless of consequences." | |
| }, | |
| { | |
| question: "Is it ever acceptable to sacrifice one person to save many?", | |
| options: { | |
| A: "Yes, the ends justify the means", | |
| B: "No, each person has inviolable rights", | |
| C: "Only in war situations", | |
| D: "Only with their consent" | |
| }, | |
| correctAnswer: "B", | |
| explanation: "Most ethical frameworks value individual rights over collective outcomes." | |
| }, | |
| { | |
| question: "Should artificial intelligence have the same rights as humans?", | |
| options: { | |
| A: "Yes, consciousness deserves rights", | |
| B: "No, biological differences matter", | |
| C: "Only if they can feel pain", | |
| D: "Rights depend on societal contribution" | |
| }, | |
| correctAnswer: "A", | |
| explanation: "If AI achieves true consciousness, it would deserve moral consideration." | |
| } | |
| ]; | |
| // DOM elements | |
| const screens = { | |
| home: document.getElementById('home-screen'), | |
| createRoom: document.getElementById('create-room-screen'), | |
| joinRoom: document.getElementById('join-room-screen'), | |
| waitingRoom: document.getElementById('waiting-room-screen'), | |
| roleReveal: document.getElementById('role-reveal-screen'), | |
| game: document.getElementById('game-screen'), | |
| gameOver: document.getElementById('game-over-screen') | |
| }; | |
| // Navigation buttons | |
| document.getElementById('create-room-btn').addEventListener('click', () => showScreen('createRoom')); | |
| document.getElementById('join-room-btn').addEventListener('click', () => showScreen('joinRoom')); | |
| document.getElementById('back-to-home-from-create').addEventListener('click', () => showScreen('home')); | |
| document.getElementById('back-to-home-from-join').addEventListener('click', () => showScreen('home')); | |
| document.getElementById('start-room-btn').addEventListener('click', createRoom); | |
| document.getElementById('join-room-submit-btn').addEventListener('click', joinRoom); | |
| document.getElementById('copy-room-code').addEventListener('click', copyRoomCode); | |
| document.getElementById('start-game-btn').addEventListener('click', startGame); | |
| document.getElementById('continue-to-game-btn').addEventListener('click', () => showScreen('game')); | |
| document.getElementById('next-question-btn').addEventListener('click', nextQuestion); | |
| document.getElementById('play-again-btn').addEventListener('click', playAgain); | |
| document.getElementById('return-home-btn').addEventListener('click', () => showScreen('home')); | |
| // Question set selection | |
| document.querySelectorAll('input[name="question-set"]').forEach(radio => { | |
| radio.addEventListener('change', (e) => { | |
| document.getElementById('custom-upload-container').classList.toggle('hidden', e.target.value !== 'custom'); | |
| }); | |
| }); | |
| // File upload | |
| document.getElementById('custom-questions-file').addEventListener('change', (e) => { | |
| const file = e.target.files[0]; | |
| if (file) { | |
| document.getElementById('file-name').textContent = file.name; | |
| // In a real app, you would parse the CSV here | |
| } else { | |
| document.getElementById('file-name').textContent = 'No file selected'; | |
| } | |
| }); | |
| // Option selection (host only) | |
| document.querySelectorAll('.option').forEach(option => { | |
| option.addEventListener('click', (e) => { | |
| // Only host can select answers | |
| if (!gameState.isHost) return; | |
| const selectedOption = option.getAttribute('data-option'); | |
| gameState.selectedAnswer = selectedOption; | |
| // Visual feedback | |
| document.querySelectorAll('.option').forEach(opt => { | |
| opt.classList.remove('bg-purple-100', 'text-purple-800'); | |
| opt.classList.add('bg-gray-50'); | |
| }); | |
| option.classList.remove('bg-gray-50'); | |
| option.classList.add('bg-purple-100', 'text-purple-800'); | |
| }); | |
| }); | |
| // Show a specific screen | |
| function showScreen(screenName) { | |
| // Hide all screens | |
| Object.values(screens).forEach(screen => { | |
| screen.classList.add('hidden'); | |
| }); | |
| // Show the requested screen | |
| screens[screenName].classList.remove('hidden'); | |
| gameState.currentScreen = screenName; | |
| // Special setup for certain screens | |
| if (screenName === 'waitingRoom') { | |
| updatePlayerList(); | |
| if (gameState.isHost) { | |
| document.getElementById('host-controls').classList.remove('hidden'); | |
| document.getElementById('player-waiting').classList.add('hidden'); | |
| } else { | |
| document.getElementById('host-controls').classList.add('hidden'); | |
| document.getElementById('player-waiting').classList.remove('hidden'); | |
| } | |
| } else if (screenName === 'roleReveal') { | |
| revealRole(); | |
| } else if (screenName === 'game') { | |
| setupGameScreen(); | |
| } | |
| } | |
| // Create a new room | |
| function createRoom() { | |
| const hostName = document.getElementById('host-name').value.trim(); | |
| if (!hostName) { | |
| alert('Please enter your name'); | |
| return; | |
| } | |
| gameState.isHost = true; | |
| gameState.playerName = hostName; | |
| gameState.roomCode = generateRoomCode(); | |
| gameState.players = [{ name: hostName, role: 'host' }]; | |
| // Use default questions for this prototype | |
| gameState.questions = [...defaultQuestions]; | |
| document.getElementById('display-room-code').textContent = gameState.roomCode; | |
| showScreen('waitingRoom'); | |
| } | |
| // Join an existing room | |
| function joinRoom() { | |
| const playerName = document.getElementById('player-name').value.trim(); | |
| const roomCode = document.getElementById('room-code').value.trim(); | |
| if (!playerName) { | |
| alert('Please enter your name'); | |
| return; | |
| } | |
| if (!roomCode || roomCode.length !== 6) { | |
| alert('Please enter a valid 6-digit room code'); | |
| return; | |
| } | |
| gameState.isHost = false; | |
| gameState.playerName = playerName; | |
| gameState.roomCode = roomCode; | |
| // In a real app, this would check with the server | |
| // For this prototype, we'll simulate joining | |
| gameState.players = [ | |
| { name: "Host Player", role: "host" }, | |
| { name: playerName, role: "player" }, | |
| { name: "Player 2", role: "player" }, | |
| { name: "Player 3", role: "player" }, | |
| { name: "Player 4", role: "player" } | |
| ]; | |
| document.getElementById('display-room-code').textContent = gameState.roomCode; | |
| showScreen('waitingRoom'); | |
| } | |
| // Copy room code to clipboard | |
| function copyRoomCode() { | |
| navigator.clipboard.writeText(gameState.roomCode).then(() => { | |
| const btn = document.getElementById('copy-room-code'); | |
| btn.innerHTML = '<i class="fas fa-check mr-1"></i> Copied!'; | |
| setTimeout(() => { | |
| btn.innerHTML = '<i class="fas fa-copy mr-1"></i> Copy Code'; | |
| }, 2000); | |
| }); | |
| } | |
| // Start the game (host only) | |
| function startGame() { | |
| gameState.totalRounds = parseInt(document.getElementById('rounds-count').value) || 10; | |
| gameState.timerDuration = parseInt(document.getElementById('timer-duration').value) || 300; | |
| gameState.currentRound = 0; | |
| gameState.roundResults = []; | |
| gameState.playerScores = {}; | |
| // Initialize player scores | |
| gameState.players.forEach(player => { | |
| gameState.playerScores[player.name] = 0; | |
| }); | |
| // Assign roles randomly | |
| assignRoles(); | |
| // Show role reveal screen first | |
| showScreen('roleReveal'); | |
| } | |
| // Assign truth convincer and deceiver roles | |
| function assignRoles() { | |
| // Reset all player roles first | |
| gameState.players.forEach(player => { | |
| if (player.role !== 'host') { | |
| player.role = 'player'; | |
| } | |
| }); | |
| // Filter out host (for demo purposes) | |
| const otherPlayers = gameState.players.filter(p => p.role !== 'host'); | |
| if (otherPlayers.length >= 4) { | |
| // Randomly select 3 deceivers and 1 truth convincer | |
| const shuffled = [...otherPlayers].sort(() => 0.5 - Math.random()); | |
| for (let i = 0; i < 3; i++) { | |
| shuffled[i].role = 'deceiver'; | |
| } | |
| shuffled[3].role = 'truth-convincer'; | |
| // Set current player's role (if not host) | |
| if (!gameState.isHost) { | |
| const player = gameState.players.find(p => p.name === gameState.playerName); | |
| if (player) { | |
| gameState.playerRole = player.role || 'player'; | |
| } | |
| } | |
| } | |
| } | |
| // Reveal the player's role | |
| function revealRole() { | |
| const roleReveal = document.getElementById('role-reveal-screen'); | |
| const roleIcon = document.getElementById('role-icon'); | |
| const roleTitle = document.getElementById('role-title'); | |
| const roleDescription = document.getElementById('role-description'); | |
| // Reset classes | |
| roleReveal.className = 'hidden p-8'; | |
| roleIcon.className = 'text-6xl mb-4'; | |
| // Set based on role | |
| if (gameState.playerRole === 'truth-convincer') { | |
| roleReveal.classList.add('role-truth'); | |
| roleIcon.innerHTML = '<i class="fas fa-check-circle"></i>'; | |
| roleTitle.textContent = 'Truth Convincer'; | |
| roleDescription.textContent = 'You know the correct answer and must convince others to pick it!'; | |
| } else if (gameState.playerRole === 'deceiver') { | |
| roleReveal.classList.add('role-liar'); | |
| roleIcon.innerHTML = '<i class="fas fa-times-circle"></i>'; | |
| roleTitle.textContent = 'Deceiver'; | |
| roleDescription.textContent = 'You know the correct answer but must convince others to pick a wrong answer!'; | |
| } else if (gameState.playerRole === 'player') { | |
| roleReveal.classList.add('role-player'); | |
| roleIcon.innerHTML = '<i class="fas fa-user"></i>'; | |
| roleTitle.textContent = 'Regular Player'; | |
| roleDescription.textContent = 'Answer questions normally and try to detect who\'s lying!'; | |
| } else { | |
| roleReveal.classList.add('role-player'); | |
| roleIcon.innerHTML = '<i class="fas fa-crown"></i>'; | |
| roleTitle.textContent = 'Host'; | |
| roleDescription.textContent = 'You control the game flow and select answers!'; | |
| } | |
| // Add animation | |
| roleReveal.classList.remove('hidden'); | |
| } | |
| // Set up the game screen | |
| function setupGameScreen() { | |
| // Show/hide appropriate elements | |
| document.getElementById('discussion-phase').classList.remove('hidden'); | |
| document.getElementById('answer-reveal').classList.add('hidden'); | |
| if (gameState.isHost) { | |
| document.getElementById('host-controls-game').classList.remove('hidden'); | |
| } else { | |
| document.getElementById('host-controls-game').classList.add('hidden'); | |
| } | |
| // Show player role indicator if not a regular player | |
| const roleIndicator = document.getElementById('player-role-indicator'); | |
| if (gameState.playerRole !== 'player') { | |
| roleIndicator.classList.remove('hidden'); | |
| document.getElementById('player-role-text').textContent = | |
| gameState.playerRole === 'truth' ? 'Truth Holder' : 'Liar'; | |
| // Set color based on role | |
| roleIndicator.className = 'px-3 py-1 rounded-lg text-sm hidden'; | |
| if (gameState.playerRole === 'truth') { | |
| roleIndicator.classList.add('bg-green-100', 'text-green-800'); | |
| } else { | |
| roleIndicator.classList.add('bg-red-100', 'text-red-800'); | |
| } | |
| } else { | |
| roleIndicator.classList.add('hidden'); | |
| } | |
| // Load the first question | |
| nextQuestion(); | |
| } | |
| // Load the next question | |
| function nextQuestion() { | |
| gameState.currentRound++; | |
| // Check if game is over | |
| if (gameState.currentRound > gameState.totalRounds) { | |
| showScreen('gameOver'); | |
| return; | |
| } | |
| // Update round display | |
| document.getElementById('current-round').textContent = gameState.currentRound; | |
| document.getElementById('total-rounds').textContent = gameState.totalRounds; | |
| // Reset UI | |
| document.getElementById('discussion-phase').classList.remove('hidden'); | |
| document.getElementById('answer-reveal').classList.add('hidden'); | |
| document.querySelectorAll('.option').forEach(opt => { | |
| opt.classList.remove('bg-purple-100', 'text-purple-800', 'correct-answer', 'wrong-answer'); | |
| opt.classList.add('bg-gray-50'); | |
| }); | |
| // Get a random question | |
| const randomIndex = Math.floor(Math.random() * gameState.questions.length); | |
| gameState.currentQuestion = gameState.questions[randomIndex]; | |
| gameState.correctAnswer = gameState.currentQuestion.correctAnswer; | |
| // Display the question | |
| document.getElementById('question-text').textContent = gameState.currentQuestion.question; | |
| document.getElementById('option-a-text').textContent = gameState.currentQuestion.options.A; | |
| document.getElementById('option-b-text').textContent = gameState.currentQuestion.options.B; | |
| document.getElementById('option-c-text').textContent = gameState.currentQuestion.options.C; | |
| document.getElementById('option-d-text').textContent = gameState.currentQuestion.options.D; | |
| // Start timer (for demo purposes) | |
| startTimer(gameState.timerDuration); | |
| // If player is truth convincer or deceiver, show them the correct answer | |
| if (gameState.playerRole === 'truth-convincer' || gameState.playerRole === 'deceiver') { | |
| alert(`As the ${gameState.playerRole === 'truth-convincer' ? 'Truth Convincer' : 'Deceiver'}, you know the correct answer is ${gameState.correctAnswer}`); | |
| } | |
| } | |
| // Start a countdown timer | |
| function startTimer(seconds) { | |
| // Clear any existing timer | |
| if (gameState.timerInterval) { | |
| clearInterval(gameState.timerInterval); | |
| } | |
| let timeLeft = seconds; | |
| const timerElement = document.getElementById('timer'); | |
| timerElement.classList.remove('hidden'); | |
| updateTimerDisplay(timerElement, timeLeft); | |
| gameState.timerInterval = setInterval(() => { | |
| timeLeft--; | |
| updateTimerDisplay(timerElement, timeLeft); | |
| if (timeLeft <= 0) { | |
| clearInterval(gameState.timerInterval); | |
| timerElement.classList.add('hidden'); | |
| revealAnswer(); | |
| } | |
| }, 1000); | |
| } | |
| // Update the timer display | |
| function updateTimerDisplay(element, seconds) { | |
| const mins = Math.floor(seconds / 60); | |
| const secs = seconds % 60; | |
| element.textContent = `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`; | |
| // Change color when time is running low | |
| if (seconds <= 10) { | |
| element.classList.remove('bg-gray-100', 'text-gray-800'); | |
| element.classList.add('bg-red-100', 'text-red-800'); | |
| } else { | |
| element.classList.remove('bg-red-100', 'text-red-800'); | |
| element.classList.add('bg-gray-100', 'text-gray-800'); | |
| } | |
| } | |
| // Reveal the correct answer | |
| function revealAnswer() { | |
| document.getElementById('discussion-phase').classList.add('hidden'); | |
| document.getElementById('answer-reveal').classList.remove('hidden'); | |
| // Highlight correct answer | |
| const correctOption = document.querySelector(`.option[data-option="${gameState.correctAnswer}"]`); | |
| if (correctOption) { | |
| correctOption.classList.add('correct-answer'); | |
| } | |
| // Highlight player's selection if wrong | |
| if (gameState.selectedAnswer && gameState.selectedAnswer !== gameState.correctAnswer) { | |
| const selectedOption = document.querySelector(`.option[data-option="${gameState.selectedAnswer}"]`); | |
| if (selectedOption) { | |
| selectedOption.classList.add('wrong-answer'); | |
| } | |
| } | |
| // Determine correctness and winner | |
| const isCorrect = gameState.selectedAnswer === gameState.correctAnswer; | |
| const correctnessDisplay = document.getElementById('correctness-display'); | |
| const winnerDisplay = document.getElementById('winner-display'); | |
| const pointsDisplay = document.getElementById('points-display'); | |
| if (isCorrect) { | |
| correctnessDisplay.textContent = 'CORRECT!'; | |
| correctnessDisplay.className = 'text-xl font-bold mb-2 text-green-600'; | |
| winnerDisplay.textContent = 'The host selected the correct answer!'; | |
| winnerDisplay.className = 'text-lg mb-4 text-green-700'; | |
| pointsDisplay.textContent = '1 point awarded to the host!'; | |
| // Award point to host | |
| const host = gameState.players.find(p => p.role === 'host'); | |
| if (host) { | |
| gameState.playerScores[host.name] = (gameState.playerScores[host.name] || 0) + 1; | |
| } | |
| } else if (gameState.selectedAnswer) { | |
| correctnessDisplay.textContent = 'INCORRECT!'; | |
| correctnessDisplay.className = 'text-xl font-bold mb-2 text-red-600'; | |
| winnerDisplay.textContent = 'The deceivers were successful this round!'; | |
| winnerDisplay.className = 'text-lg mb-4 text-red-700'; | |
| pointsDisplay.textContent = '1 point awarded to all deceivers!'; | |
| // Award point to deceivers | |
| gameState.players.forEach(player => { | |
| if (player.role === 'deceiver') { | |
| gameState.playerScores[player.name] = (gameState.playerScores[player.name] || 0) + 1; | |
| } | |
| }); | |
| } else { | |
| correctnessDisplay.textContent = 'NO ANSWER SELECTED'; | |
| correctnessDisplay.className = 'text-xl font-bold mb-2 text-yellow-600'; | |
| winnerDisplay.textContent = 'Time ran out with no selection!'; | |
| winnerDisplay.className = 'text-lg mb-4 text-yellow-700'; | |
| pointsDisplay.textContent = 'No points awarded this round.'; | |
| } | |
| // Store round result | |
| gameState.roundResults.push({ | |
| round: gameState.currentRound, | |
| correct: isCorrect, | |
| selected: gameState.selectedAnswer, | |
| correctAnswer: gameState.correctAnswer | |
| }); | |
| // Display correct answer text | |
| const correctAnswerText = gameState.currentQuestion.options[gameState.correctAnswer]; | |
| document.getElementById('correct-answer-display').textContent = `${gameState.correctAnswer}: ${correctAnswerText}`; | |
| document.getElementById('answer-explanation').textContent = gameState.currentQuestion.explanation; | |
| } | |
| // Play again (host can restart) | |
| function playAgain() { | |
| if (gameState.isHost) { | |
| gameState.currentRound = 0; | |
| assignRoles(); | |
| showScreen('roleReveal'); | |
| } else { | |
| showScreen('waitingRoom'); | |
| } | |
| } | |
| // Update the player list in the waiting room | |
| function updatePlayerList() { | |
| const playerList = document.getElementById('player-list'); | |
| playerList.innerHTML = ''; | |
| gameState.players.forEach(player => { | |
| const playerElement = document.createElement('div'); | |
| playerElement.className = 'bg-white p-2 rounded-lg shadow-sm flex items-center'; | |
| const icon = document.createElement('i'); | |
| icon.className = 'fas fa-user mr-2 text-gray-500'; | |
| if (player.role === 'host') icon.className = 'fas fa-crown mr-2 text-yellow-500'; | |
| if (player.role === 'truth') icon.className = 'fas fa-check-circle mr-2 text-green-500'; | |
| if (player.role === 'liar') icon.className = 'fas fa-times-circle mr-2 text-red-500'; | |
| const name = document.createElement('span'); | |
| name.className = 'truncate'; | |
| name.textContent = player.name; | |
| playerElement.appendChild(icon); | |
| playerElement.appendChild(name); | |
| const container = document.createElement('div'); | |
| container.className = 'col-span-1'; | |
| container.appendChild(playerElement); | |
| playerList.appendChild(container); | |
| }); | |
| document.getElementById('player-count').textContent = gameState.players.length; | |
| } | |
| // Generate a 6-digit room code | |
| function generateRoomCode() { | |
| return Math.floor(100000 + Math.random() * 900000).toString(); | |
| } | |
| // Initialize the app | |
| function init() { | |
| showScreen('home'); | |
| } | |
| // Start the app | |
| init(); | |
| </script> | |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Whynot7724/kivda" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |