Spaces:
Running
Running
Add 3 files
Browse files- README.md +6 -4
- index.html +468 -19
- prompts.txt +1 -0
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: red
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: snakegame
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: yellow
|
| 5 |
colorTo: red
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,468 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Customizable Snake Game</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<style>
|
| 9 |
+
#gameCanvas {
|
| 10 |
+
border: 2px solid #4a5568;
|
| 11 |
+
background-color: #f7fafc;
|
| 12 |
+
}
|
| 13 |
+
.toggle-btn {
|
| 14 |
+
transition: all 0.3s ease;
|
| 15 |
+
}
|
| 16 |
+
.toggle-btn.active {
|
| 17 |
+
background-color: #4299e1;
|
| 18 |
+
color: white;
|
| 19 |
+
}
|
| 20 |
+
.modal {
|
| 21 |
+
display: none;
|
| 22 |
+
position: fixed;
|
| 23 |
+
z-index: 10;
|
| 24 |
+
left: 0;
|
| 25 |
+
top: 0;
|
| 26 |
+
width: 100%;
|
| 27 |
+
height: 100%;
|
| 28 |
+
background-color: rgba(0, 0, 0, 0.5);
|
| 29 |
+
}
|
| 30 |
+
.modal-content {
|
| 31 |
+
background-color: #f8fafc;
|
| 32 |
+
margin: 15% auto;
|
| 33 |
+
padding: 20px;
|
| 34 |
+
border-radius: 8px;
|
| 35 |
+
max-width: 400px;
|
| 36 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 37 |
+
}
|
| 38 |
+
</style>
|
| 39 |
+
</head>
|
| 40 |
+
<body class="bg-gray-100 min-h-screen flex flex-col items-center justify-center p-4">
|
| 41 |
+
<div class="text-center mb-6">
|
| 42 |
+
<h1 class="text-4xl font-bold text-gray-800 mb-2">Custom Snake Game</h1>
|
| 43 |
+
<p class="text-gray-600">Control the snake with arrow keys or WASD</p>
|
| 44 |
+
</div>
|
| 45 |
+
|
| 46 |
+
<div class="flex flex-col md:flex-row gap-8 items-center justify-center">
|
| 47 |
+
<div class="flex flex-col items-center">
|
| 48 |
+
<canvas id="gameCanvas" width="400" height="400"></canvas>
|
| 49 |
+
<div class="mt-4 flex gap-4">
|
| 50 |
+
<button id="startBtn" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition">
|
| 51 |
+
Start Game
|
| 52 |
+
</button>
|
| 53 |
+
<button id="pauseBtn" class="px-4 py-2 bg-yellow-500 text-white rounded hover:bg-yellow-600 transition hidden">
|
| 54 |
+
Pause
|
| 55 |
+
</button>
|
| 56 |
+
<button id="restartBtn" class="px-4 py-2 bg-red-500 text-white rounded hover:bg-red-600 transition">
|
| 57 |
+
Restart
|
| 58 |
+
</button>
|
| 59 |
+
</div>
|
| 60 |
+
</div>
|
| 61 |
+
|
| 62 |
+
<div class="bg-white p-6 rounded-lg shadow-lg w-full max-w-md">
|
| 63 |
+
<h2 class="text-xl font-semibold mb-4 text-gray-800">Game Settings</h2>
|
| 64 |
+
|
| 65 |
+
<div class="mb-6">
|
| 66 |
+
<label class="block text-gray-700 mb-2">Game Speed</label>
|
| 67 |
+
<input type="range" id="speedSlider" min="5" max="25" value="10" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
|
| 68 |
+
<div class="flex justify-between text-sm text-gray-600 mt-1">
|
| 69 |
+
<span>Slow</span>
|
| 70 |
+
<span>Fast</span>
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
|
| 74 |
+
<div class="mb-6">
|
| 75 |
+
<label class="block text-gray-700 mb-2">Boundary Settings</label>
|
| 76 |
+
<p class="text-sm text-gray-500 mb-3">Select which boundaries will end the game:</p>
|
| 77 |
+
<div class="grid grid-cols-2 gap-2">
|
| 78 |
+
<button id="topBoundary" class="toggle-btn px-3 py-2 border rounded">Top</button>
|
| 79 |
+
<button id="rightBoundary" class="toggle-btn px-3 py-2 border rounded">Right</button>
|
| 80 |
+
<button id="bottomBoundary" class="toggle-btn px-3 py-2 border rounded active">Bottom</button>
|
| 81 |
+
<button id="leftBoundary" class="toggle-btn px-3 py-2 border rounded active">Left</button>
|
| 82 |
+
</div>
|
| 83 |
+
</div>
|
| 84 |
+
|
| 85 |
+
<div class="mb-4">
|
| 86 |
+
<label class="block text-gray-700 mb-2">Game Stats</label>
|
| 87 |
+
<div class="bg-gray-100 p-3 rounded">
|
| 88 |
+
<div class="flex justify-between">
|
| 89 |
+
<span class="font-medium">Score:</span>
|
| 90 |
+
<span id="scoreDisplay">0</span>
|
| 91 |
+
</div>
|
| 92 |
+
<div class="flex justify-between">
|
| 93 |
+
<span class="font-medium">High Score:</span>
|
| 94 |
+
<span id="highScoreDisplay">0</span>
|
| 95 |
+
</div>
|
| 96 |
+
</div>
|
| 97 |
+
</div>
|
| 98 |
+
|
| 99 |
+
<button id="howToPlayBtn" class="text-blue-500 hover:text-blue-700 text-sm underline">
|
| 100 |
+
How to Play
|
| 101 |
+
</button>
|
| 102 |
+
</div>
|
| 103 |
+
</div>
|
| 104 |
+
|
| 105 |
+
<!-- How to Play Modal -->
|
| 106 |
+
<div id="howToPlayModal" class="modal">
|
| 107 |
+
<div class="modal-content">
|
| 108 |
+
<div class="flex justify-between items-center mb-4">
|
| 109 |
+
<h3 class="text-lg font-semibold">How to Play</h3>
|
| 110 |
+
<button id="closeModal" class="text-gray-500 hover:text-gray-700">×</button>
|
| 111 |
+
</div>
|
| 112 |
+
<div class="space-y-3 text-gray-700">
|
| 113 |
+
<p><strong>Controls:</strong> Use arrow keys (↑, ↓, ←, →) or WASD keys to move the snake.</p>
|
| 114 |
+
<p><strong>Objective:</strong> Eat the food (red square) to grow longer and increase your score.</p>
|
| 115 |
+
<p><strong>Game Over:</strong> The game ends if you hit the selected boundaries or yourself.</p>
|
| 116 |
+
<p><strong>Customization:</strong> Adjust game speed and select which boundaries will end the game.</p>
|
| 117 |
+
</div>
|
| 118 |
+
<div class="mt-6 flex justify-center">
|
| 119 |
+
<button id="closeModalBtn" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition">
|
| 120 |
+
Got it!
|
| 121 |
+
</button>
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
</div>
|
| 125 |
+
|
| 126 |
+
<script>
|
| 127 |
+
// Game variables
|
| 128 |
+
const canvas = document.getElementById('gameCanvas');
|
| 129 |
+
const ctx = canvas.getContext('2d');
|
| 130 |
+
const boxSize = 20;
|
| 131 |
+
let snake = [];
|
| 132 |
+
let food = {};
|
| 133 |
+
let direction = 'right';
|
| 134 |
+
let nextDirection = 'right';
|
| 135 |
+
let gameSpeed = 150; // Initial slow speed (higher number = slower)
|
| 136 |
+
let gameInterval;
|
| 137 |
+
let score = 0;
|
| 138 |
+
let highScore = localStorage.getItem('snakeHighScore') || 0;
|
| 139 |
+
let gameRunning = false;
|
| 140 |
+
let gamePaused = false;
|
| 141 |
+
|
| 142 |
+
// Boundary settings
|
| 143 |
+
let boundaries = {
|
| 144 |
+
top: false,
|
| 145 |
+
right: false,
|
| 146 |
+
bottom: true,
|
| 147 |
+
left: true
|
| 148 |
+
};
|
| 149 |
+
|
| 150 |
+
// Initialize game
|
| 151 |
+
function initGame() {
|
| 152 |
+
snake = [
|
| 153 |
+
{x: 9 * boxSize, y: 10 * boxSize},
|
| 154 |
+
{x: 8 * boxSize, y: 10 * boxSize},
|
| 155 |
+
{x: 7 * boxSize, y: 10 * boxSize}
|
| 156 |
+
];
|
| 157 |
+
|
| 158 |
+
direction = 'right';
|
| 159 |
+
nextDirection = 'right';
|
| 160 |
+
score = 0;
|
| 161 |
+
updateScore();
|
| 162 |
+
generateFood();
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
// Draw game elements
|
| 166 |
+
function draw() {
|
| 167 |
+
// Clear canvas
|
| 168 |
+
ctx.fillStyle = '#f7fafc';
|
| 169 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
| 170 |
+
|
| 171 |
+
// Draw snake
|
| 172 |
+
snake.forEach((segment, index) => {
|
| 173 |
+
if (index === 0) {
|
| 174 |
+
// Draw head with different color
|
| 175 |
+
ctx.fillStyle = '#2c5282';
|
| 176 |
+
} else {
|
| 177 |
+
ctx.fillStyle = '#4299e1';
|
| 178 |
+
}
|
| 179 |
+
ctx.fillRect(segment.x, segment.y, boxSize, boxSize);
|
| 180 |
+
ctx.strokeStyle = '#ebf8ff';
|
| 181 |
+
ctx.strokeRect(segment.x, segment.y, boxSize, boxSize);
|
| 182 |
+
});
|
| 183 |
+
|
| 184 |
+
// Draw food
|
| 185 |
+
ctx.fillStyle = '#e53e3e';
|
| 186 |
+
ctx.fillRect(food.x, food.y, boxSize, boxSize);
|
| 187 |
+
|
| 188 |
+
// Draw grid (optional)
|
| 189 |
+
if (window.innerWidth > 768) { // Only show grid on larger screens
|
| 190 |
+
ctx.strokeStyle = '#e2e8f0';
|
| 191 |
+
ctx.lineWidth = 0.5;
|
| 192 |
+
for (let i = 0; i < canvas.width; i += boxSize) {
|
| 193 |
+
ctx.beginPath();
|
| 194 |
+
ctx.moveTo(i, 0);
|
| 195 |
+
ctx.lineTo(i, canvas.height);
|
| 196 |
+
ctx.stroke();
|
| 197 |
+
|
| 198 |
+
ctx.beginPath();
|
| 199 |
+
ctx.moveTo(0, i);
|
| 200 |
+
ctx.lineTo(canvas.width, i);
|
| 201 |
+
ctx.stroke();
|
| 202 |
+
}
|
| 203 |
+
}
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
// Game logic
|
| 207 |
+
function gameLoop() {
|
| 208 |
+
if (gamePaused) return;
|
| 209 |
+
|
| 210 |
+
// Update direction
|
| 211 |
+
direction = nextDirection;
|
| 212 |
+
|
| 213 |
+
// Calculate new head position
|
| 214 |
+
const head = {x: snake[0].x, y: snake[0].y};
|
| 215 |
+
|
| 216 |
+
switch (direction) {
|
| 217 |
+
case 'up':
|
| 218 |
+
head.y -= boxSize;
|
| 219 |
+
break;
|
| 220 |
+
case 'down':
|
| 221 |
+
head.y += boxSize;
|
| 222 |
+
break;
|
| 223 |
+
case 'left':
|
| 224 |
+
head.x -= boxSize;
|
| 225 |
+
break;
|
| 226 |
+
case 'right':
|
| 227 |
+
head.x += boxSize;
|
| 228 |
+
break;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
// Check for collisions
|
| 232 |
+
if (checkCollision(head)) {
|
| 233 |
+
gameOver();
|
| 234 |
+
return;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
// Add new head
|
| 238 |
+
snake.unshift(head);
|
| 239 |
+
|
| 240 |
+
// Check if snake ate food
|
| 241 |
+
if (head.x === food.x && head.y === food.y) {
|
| 242 |
+
score += 10;
|
| 243 |
+
updateScore();
|
| 244 |
+
generateFood();
|
| 245 |
+
} else {
|
| 246 |
+
// Remove tail if no food eaten
|
| 247 |
+
snake.pop();
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
// Redraw everything
|
| 251 |
+
draw();
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
// Check for collisions
|
| 255 |
+
function checkCollision(head) {
|
| 256 |
+
// Check wall collisions based on boundary settings
|
| 257 |
+
if (boundaries.top && head.y < 0) return true;
|
| 258 |
+
if (boundaries.right && head.x >= canvas.width) return true;
|
| 259 |
+
if (boundaries.bottom && head.y >= canvas.height) return true;
|
| 260 |
+
if (boundaries.left && head.x < 0) return true;
|
| 261 |
+
|
| 262 |
+
// Check self collision
|
| 263 |
+
for (let i = 0; i < snake.length; i++) {
|
| 264 |
+
if (head.x === snake[i].x && head.y === snake[i].y) {
|
| 265 |
+
return true;
|
| 266 |
+
}
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
return false;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
// Generate food at random position
|
| 273 |
+
function generateFood() {
|
| 274 |
+
const maxX = Math.floor(canvas.width / boxSize);
|
| 275 |
+
const maxY = Math.floor(canvas.height / boxSize);
|
| 276 |
+
|
| 277 |
+
let foodX, foodY;
|
| 278 |
+
let validPosition = false;
|
| 279 |
+
|
| 280 |
+
while (!validPosition) {
|
| 281 |
+
foodX = Math.floor(Math.random() * maxX) * boxSize;
|
| 282 |
+
foodY = Math.floor(Math.random() * maxY) * boxSize;
|
| 283 |
+
|
| 284 |
+
validPosition = true;
|
| 285 |
+
|
| 286 |
+
// Check if food is on snake
|
| 287 |
+
for (let i = 0; i < snake.length; i++) {
|
| 288 |
+
if (snake[i].x === foodX && snake[i].y === foodY) {
|
| 289 |
+
validPosition = false;
|
| 290 |
+
break;
|
| 291 |
+
}
|
| 292 |
+
}
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
food = {x: foodX, y: foodY};
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
// Game over
|
| 299 |
+
function gameOver() {
|
| 300 |
+
clearInterval(gameInterval);
|
| 301 |
+
gameRunning = false;
|
| 302 |
+
document.getElementById('startBtn').classList.remove('hidden');
|
| 303 |
+
document.getElementById('pauseBtn').classList.add('hidden');
|
| 304 |
+
|
| 305 |
+
// Update high score if needed
|
| 306 |
+
if (score > highScore) {
|
| 307 |
+
highScore = score;
|
| 308 |
+
localStorage.setItem('snakeHighScore', highScore);
|
| 309 |
+
updateScore();
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
// Show game over message
|
| 313 |
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.7)';
|
| 314 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
| 315 |
+
|
| 316 |
+
ctx.fillStyle = '#ffffff';
|
| 317 |
+
ctx.font = '30px Arial';
|
| 318 |
+
ctx.textAlign = 'center';
|
| 319 |
+
ctx.fillText('Game Over!', canvas.width / 2, canvas.height / 2 - 30);
|
| 320 |
+
|
| 321 |
+
ctx.font = '20px Arial';
|
| 322 |
+
ctx.fillText(`Score: ${score}`, canvas.width / 2, canvas.height / 2 + 10);
|
| 323 |
+
ctx.fillText(`High Score: ${highScore}`, canvas.width / 2, canvas.height / 2 + 40);
|
| 324 |
+
|
| 325 |
+
ctx.font = '16px Arial';
|
| 326 |
+
ctx.fillText('Press Restart to play again', canvas.width / 2, canvas.height / 2 + 80);
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
// Update score display
|
| 330 |
+
function updateScore() {
|
| 331 |
+
document.getElementById('scoreDisplay').textContent = score;
|
| 332 |
+
document.getElementById('highScoreDisplay').textContent = highScore;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
// Start game
|
| 336 |
+
function startGame() {
|
| 337 |
+
if (gameRunning) return;
|
| 338 |
+
|
| 339 |
+
initGame();
|
| 340 |
+
gameRunning = true;
|
| 341 |
+
gamePaused = false;
|
| 342 |
+
|
| 343 |
+
clearInterval(gameInterval);
|
| 344 |
+
gameInterval = setInterval(gameLoop, gameSpeed);
|
| 345 |
+
|
| 346 |
+
document.getElementById('startBtn').classList.add('hidden');
|
| 347 |
+
document.getElementById('pauseBtn').classList.remove('hidden');
|
| 348 |
+
draw();
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
// Pause game
|
| 352 |
+
function pauseGame() {
|
| 353 |
+
if (!gameRunning) return;
|
| 354 |
+
|
| 355 |
+
gamePaused = !gamePaused;
|
| 356 |
+
|
| 357 |
+
if (gamePaused) {
|
| 358 |
+
document.getElementById('pauseBtn').textContent = 'Resume';
|
| 359 |
+
|
| 360 |
+
// Draw pause message
|
| 361 |
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
|
| 362 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
| 363 |
+
|
| 364 |
+
ctx.fillStyle = '#ffffff';
|
| 365 |
+
ctx.font = '30px Arial';
|
| 366 |
+
ctx.textAlign = 'center';
|
| 367 |
+
ctx.fillText('Game Paused', canvas.width / 2, canvas.height / 2);
|
| 368 |
+
} else {
|
| 369 |
+
document.getElementById('pauseBtn').textContent = 'Pause';
|
| 370 |
+
}
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
// Restart game
|
| 374 |
+
function restartGame() {
|
| 375 |
+
clearInterval(gameInterval);
|
| 376 |
+
gameRunning = false;
|
| 377 |
+
gamePaused = false;
|
| 378 |
+
document.getElementById('startBtn').classList.remove('hidden');
|
| 379 |
+
document.getElementById('pauseBtn').classList.add('hidden');
|
| 380 |
+
document.getElementById('pauseBtn').textContent = 'Pause';
|
| 381 |
+
initGame();
|
| 382 |
+
draw();
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
// Event listeners
|
| 386 |
+
document.addEventListener('keydown', function(e) {
|
| 387 |
+
// Prevent default for arrow keys to avoid page scrolling
|
| 388 |
+
if ([37, 38, 39, 40].indexOf(e.keyCode) > -1) {
|
| 389 |
+
e.preventDefault();
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
// Change direction based on key press
|
| 393 |
+
switch(e.keyCode) {
|
| 394 |
+
case 37: // left arrow
|
| 395 |
+
case 65: // A
|
| 396 |
+
if (direction !== 'right') nextDirection = 'left';
|
| 397 |
+
break;
|
| 398 |
+
case 38: // up arrow
|
| 399 |
+
case 87: // W
|
| 400 |
+
if (direction !== 'down') nextDirection = 'up';
|
| 401 |
+
break;
|
| 402 |
+
case 39: // right arrow
|
| 403 |
+
case 68: // D
|
| 404 |
+
if (direction !== 'left') nextDirection = 'right';
|
| 405 |
+
break;
|
| 406 |
+
case 40: // down arrow
|
| 407 |
+
case 83: // S
|
| 408 |
+
if (direction !== 'up') nextDirection = 'down';
|
| 409 |
+
break;
|
| 410 |
+
case 32: // space
|
| 411 |
+
if (gameRunning) pauseGame();
|
| 412 |
+
break;
|
| 413 |
+
}
|
| 414 |
+
});
|
| 415 |
+
|
| 416 |
+
// UI event listeners
|
| 417 |
+
document.getElementById('startBtn').addEventListener('click', startGame);
|
| 418 |
+
document.getElementById('pauseBtn').addEventListener('click', pauseGame);
|
| 419 |
+
document.getElementById('restartBtn').addEventListener('click', restartGame);
|
| 420 |
+
|
| 421 |
+
// Speed control
|
| 422 |
+
document.getElementById('speedSlider').addEventListener('input', function() {
|
| 423 |
+
// Map slider value (5-25) to game speed (300-50ms)
|
| 424 |
+
gameSpeed = 300 - (this.value * 10);
|
| 425 |
+
|
| 426 |
+
if (gameRunning) {
|
| 427 |
+
clearInterval(gameInterval);
|
| 428 |
+
gameInterval = setInterval(gameLoop, gameSpeed);
|
| 429 |
+
}
|
| 430 |
+
});
|
| 431 |
+
|
| 432 |
+
// Boundary toggles
|
| 433 |
+
const boundaryButtons = ['top', 'right', 'bottom', 'left'];
|
| 434 |
+
boundaryButtons.forEach(boundary => {
|
| 435 |
+
document.getElementById(`${boundary}Boundary`).addEventListener('click', function() {
|
| 436 |
+
boundaries[boundary] = !boundaries[boundary];
|
| 437 |
+
this.classList.toggle('active');
|
| 438 |
+
this.classList.toggle('bg-blue-500');
|
| 439 |
+
this.classList.toggle('text-white');
|
| 440 |
+
});
|
| 441 |
+
});
|
| 442 |
+
|
| 443 |
+
// How to Play modal
|
| 444 |
+
const modal = document.getElementById('howToPlayModal');
|
| 445 |
+
document.getElementById('howToPlayBtn').addEventListener('click', function() {
|
| 446 |
+
modal.style.display = 'block';
|
| 447 |
+
});
|
| 448 |
+
|
| 449 |
+
document.getElementById('closeModal').addEventListener('click', function() {
|
| 450 |
+
modal.style.display = 'none';
|
| 451 |
+
});
|
| 452 |
+
|
| 453 |
+
document.getElementById('closeModalBtn').addEventListener('click', function() {
|
| 454 |
+
modal.style.display = 'none';
|
| 455 |
+
});
|
| 456 |
+
|
| 457 |
+
window.addEventListener('click', function(event) {
|
| 458 |
+
if (event.target === modal) {
|
| 459 |
+
modal.style.display = 'none';
|
| 460 |
+
}
|
| 461 |
+
});
|
| 462 |
+
|
| 463 |
+
// Initialize game display
|
| 464 |
+
initGame();
|
| 465 |
+
draw();
|
| 466 |
+
</script>
|
| 467 |
+
<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=durgaamma2005/snakegame" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 468 |
+
</html>
|
prompts.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Create a snake game with speed control on the menu. The game should start at a very slow speed and not end the game immediately because of its high speed. And also give control whether which side of rectangle can be treated as out.
|