Download index.html from AndyGG/neonsnake: direct link, hf CLI and curl.
- Browser
- Download file 15.3 kB
-
https://huggingface.co/spaces/AndyGG/neonsnake/resolve/main/index.html
- Command line
-
hf download hf://spaces/AndyGG/neonsnake/index.html
-
curl -L -o index.html https://huggingface.co/spaces/AndyGG/neonsnake/resolve/main/index.html
15.3 kB
| <html lang="es"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Neon Snake Game</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <style> | |
| @import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap'); | |
| body { | |
| font-family: 'Press Start 2P', cursive; | |
| background-color: #0f172a; | |
| overflow: hidden; | |
| } | |
| .snake-segment { | |
| position: absolute; | |
| width: 20px; | |
| height: 20px; | |
| transition: transform 0.1s ease; | |
| z-index: 2; | |
| } | |
| .snake-head { | |
| z-index: 3; | |
| } | |
| .snake-body { | |
| filter: brightness(0.9); | |
| } | |
| .food { | |
| position: absolute; | |
| background-size: contain; | |
| background-repeat: no-repeat; | |
| background-position: center; | |
| width: 20px; | |
| height: 20px; | |
| animation: pulse 1s infinite alternate; | |
| } | |
| @keyframes pulse { | |
| from { transform: scale(1); } | |
| to { transform: scale(1.1); } | |
| } | |
| .game-container { | |
| position: relative; | |
| border: 4px solid #4ade80; | |
| box-shadow: 0 0 30px rgba(74, 222, 128, 0.5); | |
| margin: auto; | |
| background-color: rgba(15, 23, 42, 0.7); | |
| } | |
| .score-display { | |
| text-shadow: 0 0 5px #4ade80; | |
| } | |
| .mobile-controls { | |
| display: none; | |
| } | |
| @media (max-width: 768px) { | |
| .mobile-controls { | |
| display: grid; | |
| grid-template-columns: repeat(3, 1fr); | |
| grid-template-rows: repeat(2, 1fr); | |
| gap: 10px; | |
| margin-top: 20px; | |
| } | |
| .mobile-control-btn { | |
| background: rgba(30, 41, 59, 0.7); | |
| color: #4ade80; | |
| border: 2px solid #4ade80; | |
| border-radius: 8px; | |
| padding: 15px; | |
| font-size: 20px; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| cursor: pointer; | |
| user-select: none; | |
| box-shadow: 0 0 10px rgba(74, 222, 128, 0.3); | |
| } | |
| } | |
| .modal { | |
| background-color: rgba(15, 23, 42, 0.9); | |
| border: 3px solid #4ade80; | |
| box-shadow: 0 0 30px rgba(74, 222, 128, 0.7); | |
| } | |
| .btn-primary { | |
| background-color: #4ade80; | |
| color: #0f172a; | |
| transition: all 0.3s; | |
| } | |
| .btn-primary:hover { | |
| background-color: #22c55e; | |
| transform: translateY(-2px); | |
| box-shadow: 0 5px 15px rgba(74, 222, 128, 0.4); | |
| } | |
| </style> | |
| </head> | |
| <body class="min-h-screen flex flex-col items-center justify-center px-4"> | |
| <div class="text-center mb-6"> | |
| <h1 class="text-3xl md:text-5xl font-bold text-green-400 mb-2">NEON SNAKE</h1> | |
| <div class="score-display text-xl md:text-2xl text-green-400">Score: <span id="score">0</span></div> | |
| </div> | |
| <div class="relative"> | |
| <div id="game-container" class="game-container w-full max-w-lg aspect-square"></div> | |
| <div id="game-over-modal" class="modal hidden absolute inset-0 flex flex-col items-center justify-center p-6 text-center"> | |
| <h2 class="text-2xl md:text-3xl text-red-400 mb-4">Game Over!</h2> | |
| <p class="text-green-400 mb-6">Your score: <span id="final-score" class="text-xl">0</span></p> | |
| <button id="restart-btn" class="btn-primary px-6 py-3 rounded-lg font-bold">Play Again</button> | |
| </div> | |
| <div id="start-modal" class="modal absolute inset-0 flex flex-col items-center justify-center p-6 text-center"> | |
| <h2 class="text-2xl md:text-3xl text-green-400 mb-4">NEON SNAKE</h2> | |
| <p class="text-white mb-6">Use arrow keys or swipe to move</p> | |
| <button id="start-btn" class="btn-primary px-6 py-3 rounded-lg font-bold">Start Game</button> | |
| </div> | |
| </div> | |
| <div class="mobile-controls mt-6 w-full max-w-md"> | |
| <div></div> | |
| <button id="up-btn" class="mobile-control-btn">β</button> | |
| <div></div> | |
| <button id="left-btn" class="mobile-control-btn">β</button> | |
| <button id="down-btn" class="mobile-control-btn">β</button> | |
| <button id="right-btn" class="mobile-control-btn">β</button> | |
| </div> | |
| <div class="mt-8 text-center text-gray-400 text-sm"> | |
| <p>Arrow keys to move β’ Desktop: Click to start β’ Mobile: Tap controls</p> | |
| </div> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', () => { | |
| // Game variables | |
| const gridSize = 20; | |
| const tileSize = 20; | |
| const fruits = [ | |
| 'π', 'π', 'π', 'π', 'π', 'π', 'π', 'π', 'π', 'π', 'π', 'π₯' | |
| ]; | |
| let currentFruit = fruits[Math.floor(Math.random() * fruits.length)]; | |
| let snake = [{x: 10, y: 10}]; | |
| let food = {x: 5, y: 5}; | |
| let direction = {x: 0, y: 0}; | |
| let lastDirection = {x: 0, y: 0}; | |
| let speed = 200; | |
| let score = 0; | |
| let gameRunning = false; | |
| let gameInterval; | |
| let touchStartX = 0; | |
| let touchStartY = 0; | |
| // DOM elements | |
| const gameContainer = document.getElementById('game-container'); | |
| const scoreElement = document.getElementById('score'); | |
| const finalScoreElement = document.getElementById('final-score'); | |
| const gameOverModal = document.getElementById('game-over-modal'); | |
| const startModal = document.getElementById('start-modal'); | |
| const restartBtn = document.getElementById('restart-btn'); | |
| const startBtn = document.getElementById('start-btn'); | |
| const upBtn = document.getElementById('up-btn'); | |
| const downBtn = document.getElementById('down-btn'); | |
| const leftBtn = document.getElementById('left-btn'); | |
| const rightBtn = document.getElementById('right-btn'); | |
| // Set game container size | |
| const containerSize = gridSize * tileSize; | |
| gameContainer.style.width = `${containerSize}px`; | |
| gameContainer.style.height = `${containerSize}px`; | |
| // Mobile controls | |
| upBtn.addEventListener('click', () => changeDirection({x: 0, y: -1})); | |
| downBtn.addEventListener('click', () => changeDirection({x: 0, y: 1})); | |
| leftBtn.addEventListener('click', () => changeDirection({x: -1, y: 0})); | |
| rightBtn.addEventListener('click', () => changeDirection({x: 1, y: 0})); | |
| // Touch controls for mobile | |
| gameContainer.addEventListener('touchstart', (e) => { | |
| if (!gameRunning) { | |
| startGame(); | |
| } else { | |
| touchStartX = e.touches[0].clientX; | |
| touchStartY = e.touches[0].clientY; | |
| } | |
| }); | |
| gameContainer.addEventListener('touchmove', (e) => { | |
| e.preventDefault(); | |
| const touchEndX = e.touches[0].clientX; | |
| const touchEndY = e.touches[0].clientY; | |
| const dx = touchEndX - touchStartX; | |
| const dy = touchEndY - touchStartY; | |
| if (Math.abs(dx) > Math.abs(dy)) { | |
| // Horizontal swipe | |
| if (dx > 0 && lastDirection.x !== -1) { | |
| changeDirection({x: 1, y: 0}); | |
| } else if (dx < 0 && lastDirection.x !== 1) { | |
| changeDirection({x: -1, y: 0}); | |
| } | |
| } else { | |
| // Vertical swipe | |
| if (dy > 0 && lastDirection.y !== -1) { | |
| changeDirection({x: 0, y: 1}); | |
| } else if (dy < 0 && lastDirection.y !== 1) { | |
| changeDirection({x: 0, y: -1}); | |
| } | |
| } | |
| touchStartX = touchEndX; | |
| touchStartY = touchEndY; | |
| }); | |
| // Keyboard controls | |
| document.addEventListener('keydown', (e) => { | |
| if (!gameRunning) { | |
| if (e.key === ' ' || e.key === 'Enter' || e.key === 'ArrowUp' || e.key === 'ArrowDown' || e.key === 'ArrowLeft' || e.key === 'ArrowRight') { | |
| startGame(); | |
| return; | |
| } | |
| } | |
| switch(e.key) { | |
| case 'ArrowUp': | |
| if (lastDirection.y !== 1) changeDirection({x: 0, y: -1}); | |
| break; | |
| case 'ArrowDown': | |
| if (lastDirection.y !== -1) changeDirection({x: 0, y: 1}); | |
| break; | |
| case 'ArrowLeft': | |
| if (lastDirection.x !== 1) changeDirection({x: -1, y: 0}); | |
| break; | |
| case 'ArrowRight': | |
| if (lastDirection.x !== -1) changeDirection({x: 1, y: 0}); | |
| break; | |
| } | |
| }); | |
| // Start/Restart buttons | |
| startBtn.addEventListener('click', startGame); | |
| restartBtn.addEventListener('click', startGame); | |
| // Click/tap to start on game container | |
| gameContainer.addEventListener('click', (e) => { | |
| if (!gameRunning) { | |
| startGame(); | |
| e.preventDefault(); | |
| } | |
| }); | |
| // Functions | |
| function startGame() { | |
| snake = [{x: 10, y: 10}]; | |
| direction = {x: 0, y: 0}; | |
| lastDirection = {x: 0, y: 0}; | |
| score = 0; | |
| scoreElement.textContent = score; | |
| generateFood(); | |
| startModal.classList.add('hidden'); | |
| gameOverModal.classList.add('hidden'); | |
| gameRunning = true; | |
| if (gameInterval) clearInterval(gameInterval); | |
| gameInterval = setInterval(updateGame, speed); | |
| } | |
| function changeDirection(newDir) { | |
| // Prevent reversing direction | |
| if (newDir.x && newDir.x === -direction.x) return; | |
| if (newDir.y && newDir.y === -direction.y) return; | |
| direction = newDir; | |
| } | |
| function updateGame() { | |
| lastDirection = {...direction}; | |
| // Move snake | |
| const head = {...snake[0]}; | |
| head.x += direction.x; | |
| head.y += direction.y; | |
| // Check collisions | |
| if ( | |
| head.x < 0 || head.x >= gridSize || | |
| head.y < 0 || head.y >= gridSize || | |
| snake.some(segment => segment.x === head.x && segment.y === head.y) | |
| ) { | |
| gameOver(); | |
| return; | |
| } | |
| snake.unshift(head); | |
| // Check if snake ate food | |
| if (head.x === food.x && head.y === food.y) { | |
| score += 10; | |
| scoreElement.textContent = score; | |
| // Increase speed slightly every 50 points | |
| if (score % 50 === 0 && speed > 80) { | |
| speed -= 5; | |
| clearInterval(gameInterval); | |
| gameInterval = setInterval(updateGame, speed); | |
| } | |
| generateFood(); | |
| } else { | |
| snake.pop(); | |
| } | |
| renderGame(); | |
| } | |
| function generateFood() { | |
| let newFood; | |
| do { | |
| newFood = { | |
| x: Math.floor(Math.random() * gridSize), | |
| y: Math.floor(Math.random() * gridSize) | |
| }; | |
| } while (snake.some(segment => segment.x === newFood.x && segment.y === newFood.y)); | |
| food = newFood; | |
| currentFruit = fruits[Math.floor(Math.random() * fruits.length)]; | |
| } | |
| function renderGame() { | |
| // Clear game container | |
| gameContainer.innerHTML = ''; | |
| // Render snake | |
| snake.forEach((segment, index) => { | |
| const segmentElement = document.createElement('div'); | |
| segmentElement.className = 'snake-segment'; | |
| segmentElement.style.left = `${segment.x * tileSize}px`; | |
| segmentElement.style.top = `${segment.y * tileSize}px`; | |
| segmentElement.textContent = index === 0 ? 'π' : 'π’'; // Cabeza y cuerpo | |
| segmentElement.style.fontSize = '20px'; | |
| gameContainer.appendChild(segmentElement); | |
| }); | |
| // Render food | |
| const foodElement = document.createElement('div'); | |
| foodElement.className = 'food'; | |
| foodElement.style.left = `${food.x * tileSize}px`; | |
| foodElement.style.top = `${food.y * tileSize}px`; | |
| foodElement.textContent = currentFruit; | |
| foodElement.style.fontSize = '20px'; | |
| gameContainer.appendChild(foodElement); | |
| } | |
| function gameOver() { | |
| clearInterval(gameInterval); | |
| gameRunning = false; | |
| finalScoreElement.textContent = score; | |
| gameOverModal.classList.remove('hidden'); | |
| } | |
| // Initial setup | |
| renderGame(); | |
| }); | |
| </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=AndyGG/neonsnake" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |