Download index.html from asser829/game: direct link, hf CLI and curl.
- Browser
- Download file 47 kB
-
https://huggingface.co/spaces/asser829/game/resolve/main/index.html
- Command line
-
hf download hf://spaces/asser829/game/index.html
-
curl -L -o index.html https://huggingface.co/spaces/asser829/game/resolve/main/index.html
47 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Join Game</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <style> | |
| @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap'); | |
| body { | |
| font-family: 'Poppins', sans-serif; | |
| background-color: #1A2A80; | |
| color: white; | |
| } | |
| .floating { | |
| animation: floating 3s ease-in-out infinite; | |
| } | |
| @keyframes floating { | |
| 0% { transform: translateY(0px); } | |
| 50% { transform: translateY(-15px); } | |
| 100% { transform: translateY(0px); } | |
| } | |
| </style> | |
| </head> | |
| <body class="min-h-screen flex items-center justify-center"> | |
| <div class="max-w-md w-full mx-4"> | |
| <div class="floating mb-12 text-center"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-24 w-24 mx-auto text-[#B2B0E8]" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" /> | |
| </svg> | |
| </div> | |
| <div class="bg-[#3B38A0] bg-opacity-50 rounded-xl p-8"> | |
| <h1 class="text-3xl font-bold mb-2 text-center">Join Game</h1> | |
| <p class="text-[#B2B0E8] text-center mb-8">Enter the 4-digit code from the host</p> | |
| <form id="joinForm" class="space-y-6"> | |
| <div> | |
| <input | |
| id="roomCodeInput" | |
| type="text" | |
| maxlength="4" | |
| pattern="[A-Za-z0-9]{4}" | |
| class="w-full bg-[#1A2A80] text-white p-4 rounded-lg text-center text-2xl font-mono tracking-widest focus:outline-none focus:ring-2 focus:ring-[#B2B0E8]" | |
| placeholder="ABCD" | |
| required | |
| autofocus | |
| > | |
| </div> | |
| <button | |
| type="submit" | |
| class="w-full bg-[#B2B0E8] hover:bg-[#7A85C1] text-[#1A2A80] font-bold py-3 px-4 rounded-lg transition-all" | |
| > | |
| Join Game | |
| </button> | |
| </form> | |
| </div> | |
| </div> | |
| <script> | |
| document.getElementById('joinForm').addEventListener('submit', function(e) { | |
| e.preventDefault(); | |
| const roomCode = document.getElementById('roomCodeInput').value.toUpperCase(); | |
| if (roomCode.length === 4) { | |
| // In a real app, you would validate the room code with the server | |
| // For now, just redirect to the controller page with the code | |
| window.location.href = `/controller.html?room=${roomCode}`; | |
| } else { | |
| alert('Please enter a valid 4-character room code'); | |
| } | |
| }); | |
| // Auto-uppercase and limit to 4 chars | |
| document.getElementById('roomCodeInput').addEventListener('input', function(e) { | |
| this.value = this.value.toUpperCase().substring(0, 4); | |
| }); | |
| </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=asser829/game" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> | |
| <html lang="en" dir="ltr"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Mobile Game Controller</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/gsap@3.11.4/dist/gsap.min.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/qrcode@1.5.1/build/qrcode.min.js"></script> | |
| <style> | |
| @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap'); | |
| :root { | |
| --primary: #B2B0E8; | |
| --secondary: #7A85C1; | |
| --accent: #3B38A0; | |
| --dark: #1A2A80; | |
| } | |
| body { | |
| font-family: 'Poppins', sans-serif; | |
| transition: background-color 0.3s, color 0.3s; | |
| } | |
| .floating { | |
| animation: floating 3s ease-in-out infinite; | |
| } | |
| @keyframes floating { | |
| 0% { transform: translateY(0px); } | |
| 50% { transform: translateY(-15px); } | |
| 100% { transform: translateY(0px); } | |
| } | |
| .pulse { | |
| animation: pulse 2s infinite; | |
| } | |
| @keyframes pulse { | |
| 0% { box-shadow: 0 0 0 0 rgba(178, 176, 232, 0.7); } | |
| 70% { box-shadow: 0 0 0 10px rgba(178, 176, 232, 0); } | |
| 100% { box-shadow: 0 0 0 0 rgba(178, 176, 232, 0); } | |
| } | |
| .slide-in { | |
| animation: slideIn 0.5s forwards; | |
| } | |
| @keyframes slideIn { | |
| from { transform: translateX(100%); opacity: 0; } | |
| to { transform: translateX(0); opacity: 1; } | |
| } | |
| .fade-in { | |
| animation: fadeIn 0.5s forwards; | |
| } | |
| @keyframes fadeIn { | |
| from { opacity: 0; } | |
| to { opacity: 1; } | |
| } | |
| .controller-btn { | |
| transition: all 0.2s; | |
| } | |
| .controller-btn:active { | |
| transform: scale(0.95); | |
| background-color: var(--accent); | |
| } | |
| .game-card:hover { | |
| transform: translateY(-5px); | |
| box-shadow: 0 10px 20px rgba(0,0,0,0.2); | |
| } | |
| .rtl { | |
| direction: rtl; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-[#1A2A80] text-white min-h-screen"> | |
| <!-- Language Toggle --> | |
| <div class="fixed top-4 right-4 z-50"> | |
| <button id="languageToggle" class="bg-[#3B38A0] hover:bg-[#7A85C1] text-white px-4 py-2 rounded-full font-medium transition-all"> | |
| العربية | |
| </button> | |
| </div> | |
| <!-- Dark/Light Mode Toggle --> | |
| <div class="fixed top-4 left-4 z-50"> | |
| <button id="themeToggle" class="bg-[#3B38A0] hover:bg-[#7A85C1] text-white p-2 rounded-full transition-all"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" /> | |
| </svg> | |
| </button> | |
| </div> | |
| <!-- Main Content --> | |
| <div id="app" class="container mx-auto px-4 py-16"> | |
| <!-- Host Screen (Desktop) --> | |
| <div id="hostScreen" class="hidden"> | |
| <div class="text-center mb-12"> | |
| <h1 id="hostTitle" class="text-4xl md:text-5xl font-bold mb-4">Game Host</h1> | |
| <p id="hostSubtitle" class="text-xl text-[#B2B0E8]">Turn any mobile device into a game controller</p> | |
| </div> | |
| <div class="flex flex-col lg:flex-row gap-8"> | |
| <!-- Game Selection --> | |
| <div class="lg:w-2/3"> | |
| <h2 id="gameSelectionTitle" class="text-2xl font-semibold mb-6">Select a Game</h2> | |
| <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"> | |
| <!-- Game cards will be dynamically inserted here --> | |
| </div> | |
| </div> | |
| <!-- Player Connection --> | |
| <div class="lg:w-1/3 bg-[#3B38A0] bg-opacity-50 rounded-xl p-6"> | |
| <h2 id="connectionTitle" class="text-2xl font-semibold mb-6">Player Connection</h2> | |
| <div class="mb-6"> | |
| <div class="flex justify-between items-center mb-2"> | |
| <span id="roomCodeLabel">Room Code:</span> | |
| <span id="roomCode" class="font-mono text-xl bg-[#1A2A80] px-3 py-1 rounded">ABCD</span> | |
| </div> | |
| <div class="flex items-center justify-center my-6"> | |
| <div id="qrCode" class="p-4 bg-white rounded-lg"></div> | |
| </div> | |
| <div class="text-center mb-4"> | |
| <span id="orText">OR</span> | |
| </div> | |
| <div class="flex items-center"> | |
| <input id="roomUrl" type="text" readonly class="flex-grow bg-[#1A2A80] text-white p-2 rounded-l-lg focus:outline-none" value="https://game-controller.com/join/ABCD"> | |
| <button id="copyUrlBtn" class="bg-[#7A85C1] hover:bg-[#B2B0E8] text-white px-4 py-2 rounded-r-lg transition-all"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3" /> | |
| </svg> | |
| </button> | |
| </div> | |
| </div> | |
| <div class="mb-6"> | |
| <h3 id="connectedPlayersTitle" class="text-xl font-medium mb-3">Connected Players (0)</h3> | |
| <div id="connectedPlayers" class="space-y-2"> | |
| <!-- Players will be added here dynamically --> | |
| </div> | |
| </div> | |
| <div class="mb-6"> | |
| <h3 id="gameModeTitle" class="text-xl font-medium mb-3">Game Mode</h3> | |
| <div class="grid grid-cols-3 gap-2"> | |
| <button id="mode1v1" class="bg-[#7A85C1] hover:bg-[#B2B0E8] text-white py-2 px-4 rounded-lg transition-all">1v1</button> | |
| <button id="mode2v2" class="bg-[#7A85C1] hover:bg-[#B2B0E8] text-white py-2 px-4 rounded-lg transition-all">2v2</button> | |
| <button id="modeVsBot" class="bg-[#7A85C1] hover:bg-[#B2B0E8] text-white py-2 px-4 rounded-lg transition-all">Vs Bot</button> | |
| </div> | |
| </div> | |
| <button id="startGameBtn" class="w-full bg-[#B2B0E8] hover:bg-[#7A85C1] text-[#1A2A80] font-bold py-3 px-4 rounded-lg transition-all pulse"> | |
| Start Game | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Player Name Input (Mobile) --> | |
| <div id="nameInputScreen" class="hidden"> | |
| <div class="max-w-md mx-auto text-center"> | |
| <div class="floating mb-12"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-24 w-24 mx-auto text-[#B2B0E8]" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z" /> | |
| </svg> | |
| </div> | |
| <h1 id="nameInputTitle" class="text-3xl font-bold mb-4">Enter Your Name</h1> | |
| <p id="nameInputSubtitle" class="text-lg text-[#B2B0E8] mb-8">This will be displayed to other players</p> | |
| <div class="mb-6"> | |
| <input id="playerNameInput" type="text" class="w-full bg-[#3B38A0] bg-opacity-50 text-white p-4 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#B2B0E8]" placeholder="Your name"> | |
| </div> | |
| <button id="confirmNameBtn" class="w-full bg-[#B2B0E8] hover:bg-[#7A85C1] text-[#1A2A80] font-bold py-3 px-4 rounded-lg transition-all"> | |
| Continue | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Controller Screen (Mobile) --> | |
| <div id="controllerScreen" class="hidden"> | |
| <div class="text-center mb-8"> | |
| <h1 id="controllerTitle" class="text-2xl font-bold mb-2">Game Controller</h1> | |
| <p id="gameNameDisplay" class="text-lg text-[#B2B0E8]">Waiting for game to start...</p> | |
| </div> | |
| <div id="controllerLayout" class="grid grid-cols-3 gap-4"> | |
| <!-- Controller buttons will be dynamically inserted here --> | |
| </div> | |
| <div class="mt-8 text-center"> | |
| <p id="playerStatus" class="text-[#B2B0E8]">Connected as: <span id="playerNameDisplay" class="font-semibold">Player</span></p> | |
| </div> | |
| </div> | |
| <!-- Game Screen (Desktop) --> | |
| <div id="gameScreen" class="hidden"> | |
| <div class="flex justify-between items-center mb-8"> | |
| <div> | |
| <h1 id="gameTitle" class="text-3xl font-bold"></h1> | |
| <p id="gameModeDisplay" class="text-[#B2B0E8]"></p> | |
| </div> | |
| <div id="gameTimer" class="text-2xl font-mono bg-[#3B38A0] px-4 py-2 rounded-lg">00:00</div> | |
| </div> | |
| <div id="gameCanvas" class="w-full h-96 bg-[#3B38A0] bg-opacity-20 rounded-xl mb-8 flex items-center justify-center"> | |
| <p id="gameInstructions" class="text-center text-xl text-[#B2B0E8] max-w-md mx-auto"> | |
| Game will start shortly. Make sure all players are ready! | |
| </p> | |
| </div> | |
| <div id="scoreboard" class="grid grid-cols-4 gap-4 mb-8"> | |
| <!-- Scoreboard will be dynamically inserted here --> | |
| </div> | |
| <div class="flex justify-center"> | |
| <button id="endGameBtn" class="bg-red-500 hover:bg-red-600 text-white font-bold py-3 px-6 rounded-lg transition-all"> | |
| End Game | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // Detect device type | |
| const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); | |
| // Game data | |
| const games = [ | |
| { id: 1, name: "Snake", description: "Classic snake game. Collect food and grow your snake without hitting walls or yourself.", difficulty: "Easy", players: "1-4" }, | |
| { id: 2, name: "Pong", description: "Paddle game where you hit the ball past your opponent's paddle.", difficulty: "Medium", players: "2-4" }, | |
| { id: 3, name: "Trivia", description: "Answer trivia questions faster than your opponents.", difficulty: "Medium", players: "1-4" }, | |
| { id: 4, name: "Memory", description: "Match pairs of cards in this memory challenge.", difficulty: "Hard", players: "1-2" }, | |
| { id: 5, name: "Reaction Tap", description: "Tap the button as soon as it lights up.", difficulty: "Easy", players: "1-4" }, | |
| { id: 6, name: "Math Race", description: "Solve math problems quickly to win the race.", difficulty: "Hard", players: "1-4" }, | |
| // Add more games as needed (total 35) | |
| ]; | |
| // Current state | |
| let currentState = { | |
| language: 'en', | |
| theme: 'dark', | |
| playerName: '', | |
| roomCode: generateRoomCode(), | |
| selectedGame: null, | |
| gameMode: '1v1', | |
| connectedPlayers: [], | |
| gameActive: false, | |
| gameTime: 0, | |
| timerInterval: null | |
| }; | |
| // WebSocket simulation (in a real app, this would connect to a real server) | |
| let socket = { | |
| send: (data) => console.log("WebSocket send:", data), | |
| close: () => console.log("WebSocket closed") | |
| }; | |
| // Initialize the app | |
| document.addEventListener('DOMContentLoaded', () => { | |
| initializeUI(); | |
| setupEventListeners(); | |
| detectInitialScreen(); | |
| generateQRCode(); | |
| renderGameCards(); | |
| // Simulate WebSocket connection | |
| setTimeout(() => { | |
| if (isMobile) { | |
| // Simulate joining a room | |
| socket.send(JSON.stringify({ type: 'join', name: currentState.playerName, room: getRoomCodeFromUrl() })); | |
| } else { | |
| // Simulate host creating a room | |
| socket.send(JSON.stringify({ type: 'create', room: currentState.roomCode })); | |
| } | |
| }, 1000); | |
| }); | |
| function initializeUI() { | |
| // Set initial theme | |
| document.documentElement.classList.add('dark'); | |
| // Set initial language | |
| updateLanguageUI(); | |
| } | |
| function setupEventListeners() { | |
| // Theme toggle | |
| document.getElementById('themeToggle').addEventListener('click', toggleTheme); | |
| // Language toggle | |
| document.getElementById('languageToggle').addEventListener('click', toggleLanguage); | |
| // Name input screen | |
| document.getElementById('confirmNameBtn').addEventListener('click', confirmPlayerName); | |
| // Host screen | |
| document.getElementById('copyUrlBtn').addEventListener('click', copyRoomUrl); | |
| document.getElementById('startGameBtn').addEventListener('click', startGame); | |
| // Game mode buttons | |
| document.getElementById('mode1v1').addEventListener('click', () => setGameMode('1v1')); | |
| document.getElementById('mode2v2').addEventListener('click', () => setGameMode('2v2')); | |
| document.getElementById('modeVsBot').addEventListener('click', () => setGameMode('vsBot')); | |
| // Game screen | |
| document.getElementById('endGameBtn').addEventListener('click', endGame); | |
| // Handle keyboard input for controller | |
| if (isMobile) { | |
| document.addEventListener('keydown', handleControllerInput); | |
| } | |
| } | |
| function detectInitialScreen() { | |
| if (isMobile) { | |
| // Check if we're joining via URL | |
| const roomCode = getRoomCodeFromUrl(); | |
| if (roomCode) { | |
| currentState.roomCode = roomCode; | |
| } | |
| showScreen('nameInputScreen'); | |
| } else { | |
| showScreen('hostScreen'); | |
| } | |
| } | |
| function showScreen(screenId) { | |
| // Hide all screens | |
| document.getElementById('hostScreen').classList.add('hidden'); | |
| document.getElementById('nameInputScreen').classList.add('hidden'); | |
| document.getElementById('controllerScreen').classList.add('hidden'); | |
| document.getElementById('gameScreen').classList.add('hidden'); | |
| // Show the requested screen | |
| document.getElementById(screenId).classList.remove('hidden'); | |
| // Animate the screen | |
| gsap.from(`#${screenId}`, { opacity: 0, y: 20, duration: 0.5 }); | |
| } | |
| function toggleTheme() { | |
| currentState.theme = currentState.theme === 'dark' ? 'light' : 'dark'; | |
| if (currentState.theme === 'dark') { | |
| document.documentElement.classList.add('dark'); | |
| document.body.classList.remove('bg-gray-100'); | |
| document.body.classList.add('bg-[#1A2A80]'); | |
| } else { | |
| document.documentElement.classList.remove('dark'); | |
| document.body.classList.remove('bg-[#1A2A80]'); | |
| document.body.classList.add('bg-gray-100'); | |
| } | |
| // Update theme toggle icon | |
| const themeIcon = document.getElementById('themeToggle').querySelector('svg'); | |
| if (currentState.theme === 'dark') { | |
| themeIcon.innerHTML = '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" />'; | |
| } else { | |
| themeIcon.innerHTML = '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z" />'; | |
| } | |
| } | |
| function toggleLanguage() { | |
| currentState.language = currentState.language === 'en' ? 'ar' : 'en'; | |
| updateLanguageUI(); | |
| } | |
| function updateLanguageUI() { | |
| const rtlElements = document.querySelectorAll('.rtl'); | |
| if (currentState.language === 'ar') { | |
| // Switch to Arabic | |
| document.getElementById('languageToggle').textContent = 'English'; | |
| // Update host screen | |
| document.getElementById('hostTitle').textContent = 'مضيف اللعبة'; | |
| document.getElementById('hostSubtitle').textContent = 'حول أي جهاز محمول إلى جهاز تحكم في الألعاب'; | |
| document.getElementById('gameSelectionTitle').textContent = 'اختر لعبة'; | |
| document.getElementById('connectionTitle').textContent = 'اتصال اللاعب'; | |
| document.getElementById('roomCodeLabel').textContent = 'رمز الغرفة:'; | |
| document.getElementById('orText').textContent = 'أو'; | |
| document.getElementById('connectedPlayersTitle').textContent = 'اللاعبون المتصلون (0)'; | |
| document.getElementById('gameModeTitle').textContent = 'وضع اللعبة'; | |
| document.getElementById('startGameBtn').textContent = 'ابدأ اللعبة'; | |
| // Update name input screen | |
| document.getElementById('nameInputTitle').textContent = 'أدخل اسمك'; | |
| document.getElementById('nameInputSubtitle').textContent = 'سيتم عرض هذا للاعبين الآخرين'; | |
| document.getElementById('playerNameInput').placeholder = 'اسمك'; | |
| document.getElementById('confirmNameBtn').textContent = 'متابعة'; | |
| // Update controller screen | |
| document.getElementById('controllerTitle').textContent = 'جهاز تحكم اللعبة'; | |
| document.getElementById('playerStatus').innerHTML = 'متصل كـ: <span id="playerNameDisplay" class="font-semibold">لاعب</span>'; | |
| // Add RTL to appropriate elements | |
| rtlElements.forEach(el => el.classList.add('rtl')); | |
| } else { | |
| // Switch to English | |
| document.getElementById('languageToggle').textContent = 'العربية'; | |
| // Update host screen | |
| document.getElementById('hostTitle').textContent = 'Game Host'; | |
| document.getElementById('hostSubtitle').textContent = 'Turn any mobile device into a game controller'; | |
| document.getElementById('gameSelectionTitle').textContent = 'Select a Game'; | |
| document.getElementById('connectionTitle').textContent = 'Player Connection'; | |
| document.getElementById('roomCodeLabel').textContent = 'Room Code:'; | |
| document.getElementById('orText').textContent = 'OR'; | |
| document.getElementById('connectedPlayersTitle').textContent = 'Connected Players (0)'; | |
| document.getElementById('gameModeTitle').textContent = 'Game Mode'; | |
| document.getElementById('startGameBtn').textContent = 'Start Game'; | |
| // Update name input screen | |
| document.getElementById('nameInputTitle').textContent = 'Enter Your Name'; | |
| document.getElementById('nameInputSubtitle').textContent = 'This will be displayed to other players'; | |
| document.getElementById('playerNameInput').placeholder = 'Your name'; | |
| document.getElementById('confirmNameBtn').textContent = 'Continue'; | |
| // Update controller screen | |
| document.getElementById('controllerTitle').textContent = 'Game Controller'; | |
| document.getElementById('playerStatus').innerHTML = 'Connected as: <span id="playerNameDisplay" class="font-semibold">Player</span>'; | |
| // Remove RTL from elements | |
| rtlElements.forEach(el => el.classList.remove('rtl')); | |
| } | |
| } | |
| function confirmPlayerName() { | |
| const nameInput = document.getElementById('playerNameInput'); | |
| const name = nameInput.value.trim(); | |
| if (name.length < 2) { | |
| alert(currentState.language === 'ar' ? 'الرجاء إدخال اسم صالح (حرفان على الأقل)' : 'Please enter a valid name (at least 2 characters)'); | |
| return; | |
| } | |
| currentState.playerName = name; | |
| document.getElementById('playerNameDisplay').textContent = name; | |
| // In a real app, we would send this to the server | |
| socket.send(JSON.stringify({ | |
| type: 'setName', | |
| name: name | |
| })); | |
| showScreen('controllerScreen'); | |
| } | |
| function generateRoomCode() { | |
| const chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; | |
| let code = ''; | |
| for (let i = 0; i < 4; i++) { | |
| code += chars.charAt(Math.floor(Math.random() * chars.length)); | |
| } | |
| return code; | |
| } | |
| function getRoomCodeFromUrl() { | |
| const url = new URL(window.location.href); | |
| const pathParts = url.pathname.split('/'); | |
| const joinIndex = pathParts.indexOf('join'); | |
| if (joinIndex !== -1 && joinIndex < pathParts.length - 1) { | |
| return pathParts[joinIndex + 1]; | |
| } | |
| return null; | |
| } | |
| function generateQRCode() { | |
| const url = `${window.location.origin}/join/${currentState.roomCode}`; | |
| document.getElementById('roomCode').textContent = currentState.roomCode; | |
| document.getElementById('roomUrl').value = url; | |
| QRCode.toCanvas(document.getElementById('qrCode'), url, { | |
| width: 180, | |
| color: { | |
| dark: '#1A2A80', | |
| light: '#ffffff' | |
| } | |
| }, (error) => { | |
| if (error) console.error(error); | |
| }); | |
| } | |
| function copyRoomUrl() { | |
| const urlInput = document.getElementById('roomUrl'); | |
| urlInput.select(); | |
| document.execCommand('copy'); | |
| // Show copied feedback | |
| const copyBtn = document.getElementById('copyUrlBtn'); | |
| const originalHtml = copyBtn.innerHTML; | |
| copyBtn.innerHTML = currentState.language === 'ar' ? 'تم النسخ!' : 'Copied!'; | |
| setTimeout(() => { | |
| copyBtn.innerHTML = originalHtml; | |
| }, 2000); | |
| } | |
| function renderGameCards() { | |
| const container = document.querySelector('#hostScreen .grid'); | |
| container.innerHTML = ''; | |
| games.forEach(game => { | |
| const difficultyColors = { | |
| Easy: 'bg-green-500', | |
| Medium: 'bg-yellow-500', | |
| Hard: 'bg-red-500' | |
| }; | |
| const card = document.createElement('div'); | |
| card.className = 'bg-[#3B38A0] bg-opacity-50 rounded-xl p-4 cursor-pointer transition-all game-card'; | |
| card.innerHTML = ` | |
| <h3 class="text-xl font-semibold mb-2">${game.name}</h3> | |
| <p class="text-[#B2B0E8] text-sm mb-3">${game.description}</p> | |
| <div class="flex justify-between items-center"> | |
| <span class="text-xs">${game.players} players</span> | |
| <span class="${difficultyColors[game.difficulty]} text-white text-xs px-2 py-1 rounded-full">${game.difficulty}</span> | |
| </div> | |
| `; | |
| card.addEventListener('click', () => selectGame(game)); | |
| container.appendChild(card); | |
| }); | |
| } | |
| function selectGame(game) { | |
| currentState.selectedGame = game; | |
| // Highlight selected game | |
| document.querySelectorAll('.game-card').forEach(card => { | |
| card.classList.remove('ring-2', 'ring-[#B2B0E8]'); | |
| }); | |
| event.currentTarget.classList.add('ring-2', 'ring-[#B2B0E8]'); | |
| // Update start game button state | |
| document.getElementById('startGameBtn').disabled = false; | |
| } | |
| function setGameMode(mode) { | |
| currentState.gameMode = mode; | |
| // Update UI | |
| document.getElementById('mode1v1').classList.remove('bg-[#B2B0E8]'); | |
| document.getElementById('mode2v2').classList.remove('bg-[#B2B0E8]'); | |
| document.getElementById('modeVsBot').classList.remove('bg-[#B2B0E8]'); | |
| document.getElementById('mode1v1').classList.add('bg-[#7A85C1]'); | |
| document.getElementById('mode2v2').classList.add('bg-[#7A85C1]'); | |
| document.getElementById('modeVsBot').classList.add('bg-[#7A85C1]'); | |
| document.getElementById(`mode${mode === '1v1' ? '1v1' : mode === '2v2' ? '2v2' : 'VsBot'}`).classList.remove('bg-[#7A85C1]'); | |
| document.getElementById(`mode${mode === '1v1' ? '1v1' : mode === '2v2' ? '2v2' : 'VsBot'}`).classList.add('bg-[#B2B0E8]'); | |
| } | |
| function startGame() { | |
| if (!currentState.selectedGame) { | |
| alert(currentState.language === 'ar' ? 'الرجاء اختيار لعبة لبدء' : 'Please select a game to start'); | |
| return; | |
| } | |
| currentState.gameActive = true; | |
| showScreen('gameScreen'); | |
| // Update game UI | |
| document.getElementById('gameTitle').textContent = currentState.selectedGame.name; | |
| document.getElementById('gameModeDisplay').textContent = `Mode: ${currentState.gameMode}`; | |
| document.getElementById('gameInstructions').textContent = getGameInstructions(currentState.selectedGame.id); | |
| // Start timer | |
| currentState.gameTime = 0; | |
| updateTimerDisplay(); | |
| currentState.timerInterval = setInterval(() => { | |
| currentState.gameTime++; | |
| updateTimerDisplay(); | |
| }, 1000); | |
| // In a real app, we would notify all players that the game has started | |
| socket.send(JSON.stringify({ | |
| type: 'startGame', | |
| game: currentState.selectedGame.id, | |
| mode: currentState.gameMode | |
| })); | |
| // Update controller screen for players | |
| updateControllerLayout(currentState.selectedGame.id); | |
| } | |
| function endGame() { | |
| currentState.gameActive = false; | |
| clearInterval(currentState.timerInterval); | |
| // In a real app, we would notify all players that the game has ended | |
| socket.send(JSON.stringify({ | |
| type: 'endGame' | |
| })); | |
| if (isMobile) { | |
| showScreen('controllerScreen'); | |
| } else { | |
| showScreen('hostScreen'); | |
| } | |
| } | |
| function updateTimerDisplay() { | |
| const minutes = Math.floor(currentState.gameTime / 60); | |
| const seconds = currentState.gameTime % 60; | |
| document.getElementById('gameTimer').textContent = | |
| `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`; | |
| } | |
| function getGameInstructions(gameId) { | |
| const instructions = { | |
| 1: "Use the arrow buttons to control your snake. Collect food to grow longer.", | |
| 2: "Use the up and down buttons to move your paddle. Hit the ball past your opponent.", | |
| 3: "When a question appears, quickly press the button with your answer.", | |
| 4: "Flip cards to find matching pairs. Remember their positions!", | |
| 5: "When the screen lights up, tap the button as fast as you can!", | |
| 6: "Solve the math problem and enter the correct answer quickly." | |
| }; | |
| return instructions[gameId] || "Follow the on-screen instructions to play the game."; | |
| } | |
| function updateControllerLayout(gameId) { | |
| const layout = document.getElementById('controllerLayout'); | |
| layout.innerHTML = ''; | |
| // Different controller layouts for different games | |
| if (gameId === 1) { | |
| // Snake game controls | |
| layout.innerHTML = ` | |
| <div class="col-start-2"> | |
| <button class="controller-btn w-full bg-[#7A85C1] hover:bg-[#B2B0E8] text-white p-4 rounded-lg" data-action="up"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 mx-auto" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18" /> | |
| </svg> | |
| </button> | |
| </div> | |
| <div class="col-span-3 flex justify-between"> | |
| <button class="controller-btn w-1/3 bg-[#7A85C1] hover:bg-[#B2B0E8] text-white p-4 rounded-lg" data-action="left"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 mx-auto" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18" /> | |
| </svg> | |
| </button> | |
| <button class="controller-btn w-1/3 bg-[#7A85C1] hover:bg-[#B2B0E8] text-white p-4 rounded-lg" data-action="right"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 mx-auto" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 5l7 7m0 0l-7 7m7-7H3" /> | |
| </svg> | |
| </button> | |
| </div> | |
| <div class="col-start-2"> | |
| <button class="controller-btn w-full bg-[#7A85C1] hover:bg-[#B2B0E8] text-white p-4 rounded-lg" data-action="down"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 mx-auto" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 14l-7 7m0 0l-7-7m7 7V3" /> | |
| </svg> | |
| </button> | |
| </div> | |
| `; | |
| } else if (gameId === 2) { | |
| // Pong game controls | |
| layout.innerHTML = ` | |
| <div class="col-span-3"> | |
| <button class="controller-btn w-full bg-[#7A85C1] hover:bg-[#B2B0E8] text-white p-8 rounded-lg" data-action="up"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 mx-auto" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18" /> | |
| </svg> | |
| </button> | |
| </div> | |
| <div class="col-span-3"> | |
| <button class="controller-btn w-full bg-[#7A85C1] hover:bg-[#B2B0E8] text-white p-8 rounded-lg" data-action="down"> | |
| <svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 mx-auto" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 14l-7 7m0 0l-7-7m7 7V3" /> | |
| </svg> | |
| </button> | |
| </div> | |
| `; | |
| } else { | |
| // Default controller for other games | |
| layout.innerHTML = ` | |
| <div class="col-span-3"> | |
| <button class="controller-btn w-full bg-[#7A85C1] hover:bg-[#B2B0E8] text-white py-6 px-4 rounded-lg text-xl font-bold" data-action="action1"> | |
| ${currentState.language === 'ar' ? 'زر ١' : 'Button 1'} | |
| </button> | |
| </div> | |
| <div class="col-span-3"> | |
| <button class="controller-btn w-full bg-[#7A85C1] hover:bg-[#B2B0E8] text-white py-6 px-4 rounded-lg text-xl font-bold" data-action="action2"> | |
| ${currentState.language === 'ar' ? 'زر ٢' : 'Button 2'} | |
| </button> | |
| </div> | |
| <div class="col-span-3"> | |
| <button class="controller-btn w-full bg-[#7A85C1] hover:bg-[#B2B0E8] text-white py-6 px-4 rounded-lg text-xl font-bold" data-action="action3"> | |
| ${currentState.language === 'ar' ? 'زر ٣' : 'Button 3'} | |
| </button> | |
| </div> | |
| <div class="col-span-3"> | |
| <button class="controller-btn w-full bg-[#7A85C1] hover:bg-[#B2B0E8] text-white py-6 px-4 rounded-lg text-xl font-bold" data-action="action4"> | |
| ${currentState.language === 'ar' ? 'زر ٤' : 'Button 4'} | |
| </button> | |
| </div> | |
| `; | |
| } | |
| // Add event listeners to controller buttons | |
| document.querySelectorAll('.controller-btn').forEach(button => { | |
| button.addEventListener('click', (e) => { | |
| const action = e.currentTarget.getAttribute('data-action'); | |
| handleControllerAction(action); | |
| }); | |
| }); | |
| } | |
| function handleControllerAction(action) { | |
| if (!currentState.gameActive) return; | |
| // In a real app, this would send the action to the server | |
| socket.send(JSON.stringify({ | |
| type: 'controllerInput', | |
| action: action, | |
| player: currentState.playerName | |
| })); | |
| // Visual feedback | |
| const button = document.querySelector(`.controller-btn[data-action="${action}"]`); | |
| gsap.to(button, { | |
| backgroundColor: '#3B38A0', | |
| duration: 0.2, | |
| onComplete: () => { | |
| gsap.to(button, { | |
| backgroundColor: '#7A85C1', | |
| duration: 0.2 | |
| }); | |
| } | |
| }); | |
| } | |
| function handleControllerInput(e) { | |
| if (!currentState.gameActive) return; | |
| let action = null; | |
| // Map keyboard keys to controller actions | |
| switch(e.key) { | |
| case 'ArrowUp': | |
| action = 'up'; | |
| break; | |
| case 'ArrowDown': | |
| action = 'down'; | |
| break; | |
| case 'ArrowLeft': | |
| action = 'left'; | |
| break; | |
| case 'ArrowRight': | |
| action = 'right'; | |
| break; | |
| case ' ': | |
| action = 'action1'; | |
| break; | |
| case 'Enter': | |
| action = 'action2'; | |
| break; | |
| } | |
| if (action) { | |
| handleControllerAction(action); | |
| e.preventDefault(); | |
| } | |
| } | |
| // Simulate WebSocket messages (for demo purposes) | |
| setInterval(() => { | |
| if (!isMobile && currentState.connectedPlayers.length < 4) { | |
| // Simulate players joining | |
| const newPlayer = `Player${Math.floor(Math.random() * 100)}`; | |
| if (!currentState.connectedPlayers.includes(newPlayer)) { | |
| currentState.connectedPlayers.push(newPlayer); | |
| updateConnectedPlayersList(); | |
| } | |
| } | |
| if (currentState.gameActive) { | |
| // Simulate game updates | |
| if (Math.random() > 0.8) { | |
| simulateGameEvent(); | |
| } | |
| } | |
| }, 3000); | |
| function updateConnectedPlayersList() { | |
| const container = document.getElementById('connectedPlayers'); | |
| container.innerHTML = ''; | |
| document.getElementById('connectedPlayersTitle').textContent = | |
| currentState.language === 'ar' | |
| ? `اللاعبون المتصلون (${currentState.connectedPlayers.length})` | |
| : `Connected Players (${currentState.connectedPlayers.length})`; | |
| currentState.connectedPlayers.forEach(player => { | |
| const playerElement = document.createElement('div'); | |
| playerElement.className = 'flex items-center bg-[#1A2A80] bg-opacity-50 p-3 rounded-lg'; | |
| playerElement.innerHTML = ` | |
| <div class="w-3 h-3 bg-green-500 rounded-full mr-3"></div> | |
| <span>${player}</span> | |
| `; | |
| container.appendChild(playerElement); | |
| }); | |
| } | |
| function simulateGameEvent() { | |
| if (!currentState.gameActive) return; | |
| // Random game events for demo | |
| const events = [ | |
| { type: 'scoreUpdate', player: currentState.connectedPlayers[0], score: Math.floor(Math.random() * 100) }, | |
| { type: 'gameMessage', message: 'Player1 scored a point!' }, | |
| { type: 'gameMessage', message: '30 seconds remaining!' }, | |
| { type: 'gameState', state: { ballPosition: { x: Math.random() * 100, y: Math.random() * 100 } } } | |
| ]; | |
| const event = events[Math.floor(Math.random() * events.length)]; | |
| switch(event.type) { | |
| case 'scoreUpdate': | |
| updateScoreboard(event.player, event.score); | |
| break; | |
| case 'gameMessage': | |
| showGameMessage(event.message); | |
| break; | |
| case 'gameState': | |
| // In a real game, this would update the game visuals | |
| break; | |
| } | |
| } | |
| function updateScoreboard(player, score) { | |
| let scoreboard = document.getElementById('scoreboard'); | |
| // For demo, just update the first player's score | |
| if (!scoreboard.querySelector('.player-score')) { | |
| // Initialize scoreboard | |
| scoreboard.innerHTML = ''; | |
| currentState.connectedPlayers.forEach((player, index) => { | |
| const playerScore = document.createElement('div'); | |
| playerScore.className = 'bg-[#3B38A0] bg-opacity-50 p-4 rounded-lg text-center'; | |
| playerScore.innerHTML = ` | |
| <div class="text-lg font-bold">${player}</div> | |
| <div class="text-3xl font-mono player-score">${index === 0 ? score : Math.floor(Math.random() * 50)}</div> | |
| `; | |
| scoreboard.appendChild(playerScore); | |
| }); | |
| } else { | |
| // Update existing scoreboard | |
| const scores = scoreboard.querySelectorAll('.player-score'); | |
| if (scores.length > 0) { | |
| scores[0].textContent = score; | |
| } | |
| } | |
| } | |
| function showGameMessage(message) { | |
| const gameCanvas = document.getElementById('gameCanvas'); | |
| const messageElement = document.createElement('div'); | |
| messageElement.className = 'bg-black bg-opacity-70 text-white px-6 py-3 rounded-lg absolute'; | |
| messageElement.textContent = message; | |
| gameCanvas.appendChild(messageElement); | |
| gsap.from(messageElement, { y: 20, opacity: 0, duration: 0.3 }); | |
| gsap.to(messageElement, { | |
| y: -20, opacity: 0, duration: 0.3, delay: 2, | |
| onComplete: () => messageElement.remove() | |
| }); | |
| } | |
| </script> | |
| </body> | |
| </html> |