NAPISZ MI GRE W SNAKE PRZEGLADARKOWA Z SUPER DESIGNERSKIM LAYOUTEM
- User
NAPISZ MI GRE W SNAKE PRZEGLADARKOWA Z SUPER DESIGNERSKIM LAYOUTEM
Assistant
Snake Game z Super Designerskim Layoutem
Oto kod gry Snake w JavaScript z nowoczesnym, designerskim interfejsem. Gra działa w przeglądarce i ma atrakcyjny wygląd.
<!DOCTYPE html> <html lang="pl"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Super Snake Game</title> <style> body { font-family: 'Arial', sans-serif; background: linear-gradient(135deg, #1a1a2e, #16213e); color: #e6e6e6; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; overflow: hidden; } .game-container { display: flex; flex-direction: column; align-items: center; background: rgba(20, 30, 50, 0.8); border-radius: 20px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); padding: 30px; width: 90%; max-width: 600px; } h1 { color: #4cc9f0; text-shadow: 0 0 10px rgba(76, 201, 240, 0.5); margin-bottom: 10px; font-size: 2.5rem; text-align: center; } .game-info { display: flex; justify-content: space-between; width: 100%; margin-bottom: 20px; padding: 0 20px; } .info-box { background: rgba(255, 255, 255, 0.1); border-radius: 10px; padding: 10px 20px; text-align: center; min-width: 100px; } .info-box h3 { margin: 0; font-size: 1rem; color: #a5a5a5; } .info-box p { margin: 5px 0 0; font-size: 1.5rem; font-weight: bold; color: #4cc9f0; } #game-board { background: rgba(0, 0, 0, 0.3); border: 2px solid rgba(76, 201, 240, 0.3); border-radius: 10px; position: relative; overflow: hidden; } #game-over { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.8); display: flex; flex-direction: column; justify-content: center; align-items: center; color: #f72585; font-size: 2rem; font-weight: bold; text-align: center; display: none; z-index: 10; } #restart-btn { margin-top: 20px; padding: 10px 20px; background: #4cc9f0; color: #1a1a2e; border: none; border-radius: 5px; font-size: 1rem; cursor: pointer; transition: all 0.3s; } #restart-btn:hover { background: #43b0e2; transform: scale(1.05); } .controls { margin-top: 20px; text-align: center; color: #a5a5a5; font-size: 0.9rem; } .controls p { margin: 5px 0; } .controls span { background: rgba(76, 201, 240, 0.2); padding: 3px 8px; border-radius: 5px; color: #4cc9f0; font-weight: bold; } @media (max-width: 600px) { .game-container { width: 95%; padding: 20px; } h1 { font-size: 2rem; } .game-info { flex-direction: column; align-items: center; gap: 10px; } } </style> </head> <body> <div class="game-container"> <h1>SUPER SNAKE</h1> <div class="game-info"> <div class="info-box"> <h3>SCORE</h3> <p id="score">0</p> </div> <div class="info-box"> <h3>LEVEL</h3> <p id="level">1</p> </div> <div class="info-box"> <h3>SPEED</h3> <p id="speed">1</p> </div> </div> <canvas id="game-board" width="400" height="400"></canvas> <div id="game-over"> <div>GAME OVER</div> <div id="final-score">SCORE: 0</div> <button id="restart-btn">PLAY AGAIN</button> </div> <div class="controls"> <p>Use <span>Arrow Keys</span> or <span>WASD</span> to control the snake</p> <p>Eat the <span style="color: #f72585;">pink food</span> to grow</p> </div> </div> <script> const canvas = document.getElementById('game-board'); const ctx = canvas.getContext('2d'); const scoreElement = document.getElementById('score'); const levelElement = document.getElementById('level'); const speedElement = document.getElementById('speed'); const gameOverElement = document.getElementById('game-over'); const finalScoreElement = document.getElementById('final-score'); const restartBtn = document.getElementById('restart-btn'); const gridSize = 20; const tileCount = canvas.width / gridSize; let snake = [ {x: 10, y: 10} ]; let food = { x: Math.floor(Math.random() * tileCount), y: Math.floor(Math.random() * tileCount) }; let xVelocity = 0; let yVelocity = 0; let score = 0; let level = 1; let speed = 1; let gameSpeed = 100; let gameRunning = true; // Kolory const colors = { background: '#1a1a2e', snake: '#4cc9f0', snakeHead: '#43b0e2', food: '#f72585', grid: 'rgba(76, 201, 240, 0.1)' }; function drawGame() { // Rysuj tło ctx.fillStyle = colors.background; ctx.fillRect(0, 0, canvas.width, canvas.height); // Rysuj siatkę ctx.strokeStyle = colors.grid; ctx.lineWidth = 0.5; for (let i = 0; i < tileCount; i++) { for (let j = 0; j < tileCount; j++) { ctx.strokeRect(i * gridSize, j * gridSize, gridSize, gridSize); } } // Rysuj węża snake.forEach((segment, index) => { ctx.fillStyle = index === 0 ? colors.snakeHead : colors.snake; ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize); // Dodaj efekt cienia dla głowy if (index === 0) { ctx.shadowColor = colors.snakeHead; ctx.shadowBlur = 10; } else { ctx.shadowBlur = 0; } }); // Rysuj jedzenie ctx.fillStyle = colors.food; ctx.beginPath(); const centerX = food.x * gridSize + gridSize / 2; const centerY = food.y * gridSize + gridSize / 2; const radius = gridSize / 2 - 2; ctx.arc(centerX, centerY, radius, 0, Math.PI * 2); ctx.fill(); // Dodaj efekt świecenia dla jedzenia ctx.shadowColor = colors.food; ctx.shadowBlur = 15; ctx.beginPath(); ctx.arc(centerX, centerY, radius, 0, Math.PI * 2); ctx.strokeStyle = 'rgba(247, 37, 133, 0.3)'; ctx.lineWidth = 5; ctx.stroke(); ctx.shadowBlur = 0; } function updateGame() { if (!gameRunning) return; // Aktualizuj pozycję węża const head = {x: snake[0].x + xVelocity, y: snake[0].y + yVelocity}; snake.unshift(head); // Sprawdź kolizję ze ścianami if (head.x < 0 || head.x >= tileCount || head.y < 0 || head.y >= tileCount) { gameOver(); return; } // Sprawdź kolizję z samym sobą for (let i = 1; i < snake.length; i++) { if (head.x === snake[i].x && head.y === snake[i].y) { gameOver(); return; } } // Sprawdź czy wąż zjadł jedzenie if (head.x === food.x && head.y === food.y) { score += 10 * level; scoreElement.textContent = score; // Co 50 punktów zwiększ poziom i prędkość if (score % 50 === 0) { level++; levelElement.textContent = level; speed = Math.min(10, Math.floor(level / 2) + 1); speedElement.textContent = speed; gameSpeed = Math.max(50, 150 - (level * 10)); } // Generuj nowe jedzenie food = { x: Math.floor(Math.random() * tileCount), y: Math.floor(Math.random() * tileCount) }; // Upewnij się, że jedzenie nie pojawia się na wężu while (snake.some(segment => segment.x === food.x && segment.y === food.y)) { food = { x: Math.floor(Math.random() * tileCount), y: Math.floor(Math.random() * tileCount) }; } } else { snake.pop(); } } function gameOver() { gameRunning = false; finalScoreElement.textContent = `SCORE: ${score}`; gameOverElement.style.display = 'flex'; } function resetGame() { snake = [{x: 10, y: 10}]; xVelocity = 0; yVelocity = 0; score = 0; level = 1; speed = 1; gameSpeed = 100; gameRunning = true; scoreElement.textContent = score; levelElement.textContent = level; speedElement.textContent = speed; gameOverElement.style.display = 'none'; food = { x: Math.floor(Math.random() * tileCount), y: Math.floor(Math.random() * tileCount) }; } function gameLoop() { updateGame(); drawGame(); if (gameRunning) { setTimeout(gameLoop, gameSpeed); } } // Obsługa klawiatury document.addEventListener('keydown', (e) => { // Zapobiegaj zmianie kierunku o 180 stopni switch(e.key) { case 'ArrowUp': case 'w': case 'W': if (yVelocity !== 1) { xVelocity = 0; yVelocity = -1; } break; case 'ArrowDown': case 's': case 'S': if (yVelocity !== -1) { xVelocity = 0; yVelocity = 1; } break; case 'ArrowLeft': case 'a': case 'A': if (xVelocity !== 1) { xVelocity = -1; yVelocity = 0; } break; case 'ArrowRight': case 'd': case 'D': if (xVelocity !== -1) { xVelocity = 1; yVelocity = 0; } break; } }); restartBtn.addEventListener('click', resetGame); // Rozpocznij grę resetGame(); gameLoop(); </script> </body> </html>Opis gry:
-
Design:
- Nowoczesny, gradientowy interfejs z ciemnym tłem
- Zaokrąglone elementy i subtelne cienie
- Animowane elementy (świecące jedzenie)
- Responsywne układy dla różnych rozmiarów ekranu
-
Funkcjonalności:
- System punktów i poziomów
- Zwiększająca się prędkość wraz z poziomem
- Efekty wizualne (cienie, gradienty)
- Obsługa zarówno strzałek jak i klawiszy WASD
- Ekran końca gry z przyciskiem restartu
-
Elementy wizualne:
- Gradientowe tło
- Przezroczyste panele informacyjne
- Animowane jedzenie w kształcie koła
- Różne kolory dla głowy i ciała węża
Gra jest gotowa do uruchomienia - wystarczy skopiować kod do pliku HTML i otworzyć w przeglądarce.
-
- User
wszystko ma byc w jednym kodzie zeby wrzucic to do html previer
Assistant
Oto kompletny kod gry Snake w jednym pliku HTML, gotowy do wstawienia do HTML Preview:
<!DOCTYPE html> <html lang="pl"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Super Snake Game</title> <style> body { font-family: 'Arial', sans-serif; background: linear-gradient(135deg, #1a1a2e, #16213e); color: #e6e6e6; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; overflow: hidden; } .game-container { display: flex; flex-direction: column; align-items: center; background: rgba(20, 30, 50, 0.8); border-radius: 20px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); padding: 30px; width: 90%; max-width: 600px; } h1 { color: #4cc9f0; text-shadow: 0 0 10px rgba(76, 201, 240, 0.5); margin-bottom: 10px; font-size: 2.5rem; text-align: center; } .game-info { display: flex; justify-content: space-between; width: 100%; margin-bottom: 20px; padding: 0 20px; } .info-box { background: rgba(255, 255, 255, 0.1); border-radius: 10px; padding: 10px 20px; text-align: center; min-width: 100px; } .info-box h3 { margin: 0; font-size: 1rem; color: #a5a5a5; } .info-box p { margin: 5px 0 0; font-size: 1.5rem; font-weight: bold; color: #4cc9f0; } #game-board { background: rgba(0, 0, 0, 0.3); border: 2px solid rgba(76, 201, 240, 0.3); border-radius: 10px; position: relative; overflow: hidden; } #game-over { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.8); display: flex; flex-direction: column; justify-content: center; align-items: center; color: #f72585; font-size: 2rem; font-weight: bold; text-align: center; display: none; z-index: 10; } #restart-btn { margin-top: 20px; padding: 10px 20px; background: #4cc9f0; color: #1a1a2e; border: none; border-radius: 5px; font-size: 1rem; cursor: pointer; transition: all 0.3s; } #restart-btn:hover { background: #43b0e2; transform: scale(1.05); } .controls { margin-top: 20px; text-align: center; color: #a5a5a5; font-size: 0.9rem; } .controls p { margin: 5px 0; } .controls span { background: rgba(76, 201, 240, 0.2); padding: 3px 8px; border-radius: 5px; color: #4cc9f0; font-weight: bold; } @media (max-width: 600px) { .game-container { width: 95%; padding: 20px; } h1 { font-size: 2rem; } .game-info { flex-direction: column; align-items: center; gap: 10px; } } </style> </head> <body> <div class="game-container"> <h1>SUPER SNAKE</h1> <div class="game-info"> <div class="info-box"> <h3>SCORE</h3> <p id="score">0</p> </div> <div class="info-box"> <h3>LEVEL</h3> <p id="level">1</p> </div> <div class="info-box"> <h3>SPEED</h3> <p id="speed">1</p> </div> </div> <canvas id="game-board" width="400" height="400"></canvas> <div id="game-over"> <div>GAME OVER</div> <div id="final-score">SCORE: 0</div> <button id="restart-btn">PLAY AGAIN</button> </div> <div class="controls"> <p>Use <span>Arrow Keys</span> or <span>WASD</span> to control the snake</p> <p>Eat the <span style="color: #f72585;">pink food</span> to grow</p> </div> </div> <script> // Inicjalizacja canvas i elementów DOM const canvas = document.getElementById('game-board'); const ctx = canvas.getContext('2d'); const scoreElement = document.getElementById('score'); const levelElement = document.getElementById('level'); const speedElement = document.getElementById('speed'); const gameOverElement = document.getElementById('game-over'); const finalScoreElement = document.getElementById('final-score'); const restartBtn = document.getElementById('restart-btn'); // Ustawienia gry const gridSize = 20; const tileCount = canvas.width / gridSize; let snake = [{x: 10, y: 10}]; let food = { x: Math.floor(Math.random() * tileCount), y: Math.floor(Math.random() * tileCount) }; let xVelocity = 0; let yVelocity = 0; let score = 0; let level = 1; let speed = 1; let gameSpeed = 100; let gameRunning = true; // Kolory const colors = { background: '#1a1a2e', snake: '#4cc9f0', snakeHead: '#43b0e2', food: '#f72585', grid: 'rgba(76, 201, 240, 0.1)' }; // Funkcja rysująca grę function drawGame() { // Rysuj tło ctx.fillStyle = colors.background; ctx.fillRect(0, 0, canvas.width, canvas.height); // Rysuj siatkę ctx.strokeStyle = colors.grid; ctx.lineWidth = 0.5; for (let i = 0; i < tileCount; i++) { for (let j = 0; j < tileCount; j++) { ctx.strokeRect(i * gridSize, j * gridSize, gridSize, gridSize); } } // Rysuj węża snake.forEach((segment, index) => { ctx.fillStyle = index === 0 ? colors.snakeHead : colors.snake; ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize); // Dodaj efekt cienia dla głowy if (index === 0) { ctx.shadowColor = colors.snakeHead; ctx.shadowBlur = 10; } else { ctx.shadowBlur = 0; } }); // Rysuj jedzenie ctx.fillStyle = colors.food; ctx.beginPath(); const centerX = food.x * gridSize + gridSize / 2; const centerY = food.y * gridSize + gridSize / 2; const radius = gridSize / 2 - 2; ctx.arc(centerX, centerY, radius, 0, Math.PI * 2); ctx.fill(); // Dodaj efekt świecenia dla jedzenia ctx.shadowColor = colors.food; ctx.shadowBlur = 15; ctx.beginPath(); ctx.arc(centerX, centerY, radius, 0, Math.PI * 2); ctx.strokeStyle = 'rgba(247, 37, 133, 0.3)'; ctx.lineWidth = 5; ctx.stroke(); ctx.shadowBlur = 0; } // Funkcja aktualizująca stan gry function updateGame() { if (!gameRunning) return; // Aktualizuj pozycję węża const head = {x: snake[0].x + xVelocity, y: snake[0].y + yVelocity}; snake.unshift(head); // Sprawdź kolizję ze ścianami if (head.x < 0 || head.x >= tileCount || head.y < 0 || head.y >= tileCount) { gameOver(); return; } // Sprawdź kolizję z samym sobą for (let i = 1; i < snake.length; i++) { if (head.x === snake[i].x && head.y === snake[i].y) { gameOver(); return; } } // Sprawdź czy wąż zjadł jedzenie if (head.x === food.x && head.y === food.y) { score += 10 * level; scoreElement.textContent = score; // Co 50 punktów zwiększ poziom i prędkość if (score % 50 === 0) { level++; levelElement.textContent = level; speed = Math.min(10, Math.floor(level / 2) + 1); speedElement.textContent = speed; gameSpeed = Math.max(50, 150 - (level * 10)); } // Generuj nowe jedzenie food = { x: Math.floor(Math.random() * tileCount), y: Math.floor(Math.random() * tileCount) }; // Upewnij się, że jedzenie nie pojawia się na wężu while (snake.some(segment => segment.x === food.x && segment.y === food.y)) { food = { x: Math.floor(Math.random() * tileCount), y: Math.floor(Math.random() * tileCount) }; } } else { snake.pop(); } } // Funkcja kończąca grę function gameOver() { gameRunning = false; finalScoreElement.textContent = `SCORE: ${score}`; gameOverElement.style.display = 'flex'; } // Funkcja resetująca grę function resetGame() { snake = [{x: 10, y: 10}]; xVelocity = 0; yVelocity = 0; score = 0; level = 1; speed = 1; gameSpeed = 100; gameRunning = true; scoreElement.textContent = score; levelElement.textContent = level; speedElement.textContent = speed; gameOverElement.style.display = 'none'; food = { x: Math.floor(Math.random() * tileCount), y: Math.floor(Math.random() * tileCount) }; } // Główna pętla gry function gameLoop() { updateGame(); drawGame(); if (gameRunning) { setTimeout(gameLoop, gameSpeed); } } // Obsługa klawiatury document.addEventListener('keydown', (e) => { // Zapobiegaj zmianie kierunku o 180 stopni switch(e.key) { case 'ArrowUp': case 'w': case 'W': if (yVelocity !== 1) { xVelocity = 0; yVelocity = -1; } break; case 'ArrowDown': case 's': case 'S': if (yVelocity !== -1) { xVelocity = 0; yVelocity = 1; } break; case 'ArrowLeft': case 'a': case 'A': if (xVelocity !== 1) { xVelocity = -1; yVelocity = 0; } break; case 'ArrowRight': case 'd': case 'D': if (xVelocity !== -1) { xVelocity = 1; yVelocity = 0; } break; } }); // Obsługa przycisku restart restartBtn.addEventListener('click', resetGame); // Rozpoczęcie gry resetGame(); gameLoop(); </script> </body> </html>Ten kod zawiera wszystko w jednym pliku HTML:
- Struktura HTML z elementami gry
- Stylizacja CSS z nowoczesnym designem
- Pełna logika gry w JavaScript
Gra jest gotowa do uruchomienia - wystarczy skopiować ten kod i wstawić go do HTML Preview. Gra ma:
- Nowoczesny, gradientowy interfejs
- System punktów i poziomów
- Zwiększającą się prędkość wraz z poziomem
- Efekty wizualne (cienie, animacje)
- Obsługę zarówno strzałek jak i klawiszy WASD
- Ekran końca gry z przyciskiem restartu
- Responsywny design dostosowujący się do różnych rozmiarów ekranu
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.