faltimiras33 commited on
Commit
8963299
·
verified ·
1 Parent(s): ba3ea0f

Add 3 files

Browse files
Files changed (3) hide show
  1. README.md +7 -5
  2. index.html +431 -19
  3. prompts.txt +1 -0
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Snake Game
3
- emoji: 📚
4
- colorFrom: blue
5
- colorTo: pink
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: snake-game
3
+ emoji: 🐳
4
+ colorFrom: gray
5
+ colorTo: yellow
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,431 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Snake Game</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <style>
9
+ @keyframes pulse {
10
+ 0%, 100% { transform: scale(1); }
11
+ 50% { transform: scale(1.1); }
12
+ }
13
+ .pulse-animation {
14
+ animation: pulse 1s infinite;
15
+ }
16
+ #game-board {
17
+ border: 2px solid #4b5563;
18
+ box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
19
+ }
20
+ .snake-segment {
21
+ transition: all 0.1s ease;
22
+ }
23
+ .food {
24
+ animation: pulse 0.5s infinite;
25
+ }
26
+ </style>
27
+ </head>
28
+ <body class="bg-gray-900 text-white min-h-screen flex flex-col items-center justify-center p-4">
29
+ <div class="text-center mb-8">
30
+ <h1 class="text-4xl md:text-5xl font-bold mb-2 text-green-400">🐍 Snake Game</h1>
31
+ <p class="text-gray-400 mb-6">Use arrow keys or swipe to control the snake</p>
32
+
33
+ <div class="flex justify-center gap-8 mb-6">
34
+ <div class="bg-gray-800 p-4 rounded-lg">
35
+ <p class="text-gray-400">Score</p>
36
+ <p id="score" class="text-2xl font-bold text-green-400">0</p>
37
+ </div>
38
+ <div class="bg-gray-800 p-4 rounded-lg">
39
+ <p class="text-gray-400">High Score</p>
40
+ <p id="high-score" class="text-2xl font-bold text-yellow-400">0</p>
41
+ </div>
42
+ </div>
43
+
44
+ <div class="flex justify-center gap-4 mb-6">
45
+ <button id="start-btn" class="bg-green-600 hover:bg-green-700 text-white px-6 py-2 rounded-lg font-bold transition">
46
+ Start Game
47
+ </button>
48
+ <button id="pause-btn" class="bg-yellow-600 hover:bg-yellow-700 text-white px-6 py-2 rounded-lg font-bold transition hidden">
49
+ Pause
50
+ </button>
51
+ </div>
52
+ </div>
53
+
54
+ <div class="relative">
55
+ <canvas id="game-board" width="400" height="400" class="bg-gray-800 rounded-lg"></canvas>
56
+
57
+ <div id="game-over" class="absolute inset-0 bg-black bg-opacity-70 flex flex-col items-center justify-center rounded-lg hidden">
58
+ <h2 class="text-3xl font-bold text-red-500 mb-4">Game Over!</h2>
59
+ <p class="text-xl mb-6">Your score: <span id="final-score" class="text-green-400">0</span></p>
60
+ <button id="restart-btn" class="bg-green-600 hover:bg-green-700 text-white px-6 py-2 rounded-lg font-bold transition">
61
+ Play Again
62
+ </button>
63
+ </div>
64
+
65
+ <div id="mobile-controls" class="mt-4 grid grid-cols-3 gap-2 md:hidden">
66
+ <div></div>
67
+ <button id="up-btn" class="bg-gray-700 hover:bg-gray-600 text-white p-4 rounded-lg font-bold transition">
68
+
69
+ </button>
70
+ <div></div>
71
+ <button id="left-btn" class="bg-gray-700 hover:bg-gray-600 text-white p-4 rounded-lg font-bold transition">
72
+
73
+ </button>
74
+ <button id="down-btn" class="bg-gray-700 hover:bg-gray-600 text-white p-4 rounded-lg font-bold transition">
75
+
76
+ </button>
77
+ <button id="right-btn" class="bg-gray-700 hover:bg-gray-600 text-white p-4 rounded-lg font-bold transition">
78
+
79
+ </button>
80
+ </div>
81
+ </div>
82
+
83
+ <div class="mt-8 text-gray-500 text-sm">
84
+ <p>Created with HTML, CSS, and JavaScript</p>
85
+ </div>
86
+
87
+ <script>
88
+ document.addEventListener('DOMContentLoaded', () => {
89
+ const canvas = document.getElementById('game-board');
90
+ const ctx = canvas.getContext('2d');
91
+ const scoreElement = document.getElementById('score');
92
+ const highScoreElement = document.getElementById('high-score');
93
+ const startBtn = document.getElementById('start-btn');
94
+ const pauseBtn = document.getElementById('pause-btn');
95
+ const restartBtn = document.getElementById('restart-btn');
96
+ const gameOverScreen = document.getElementById('game-over');
97
+ const finalScoreElement = document.getElementById('final-score');
98
+
99
+ // Mobile controls
100
+ const upBtn = document.getElementById('up-btn');
101
+ const downBtn = document.getElementById('down-btn');
102
+ const leftBtn = document.getElementById('left-btn');
103
+ const rightBtn = document.getElementById('right-btn');
104
+
105
+ // Game settings
106
+ const gridSize = 20;
107
+ const tileCount = canvas.width / gridSize;
108
+ let speed = 7;
109
+
110
+ // Game state
111
+ let snake = [];
112
+ let food = {};
113
+ let direction = 'right';
114
+ let nextDirection = 'right';
115
+ let score = 0;
116
+ let highScore = localStorage.getItem('snakeHighScore') || 0;
117
+ let gameRunning = false;
118
+ let gamePaused = false;
119
+ let gameLoop;
120
+
121
+ highScoreElement.textContent = highScore;
122
+
123
+ // Initialize game
124
+ function initGame() {
125
+ snake = [
126
+ {x: 10, y: 10},
127
+ {x: 9, y: 10},
128
+ {x: 8, y: 10}
129
+ ];
130
+
131
+ generateFood();
132
+ direction = 'right';
133
+ nextDirection = 'right';
134
+ score = 0;
135
+ scoreElement.textContent = score;
136
+ gameOverScreen.classList.add('hidden');
137
+
138
+ if (gameLoop) clearInterval(gameLoop);
139
+ gameRunning = true;
140
+ gamePaused = false;
141
+ startBtn.classList.add('hidden');
142
+ pauseBtn.classList.remove('hidden');
143
+ pauseBtn.textContent = 'Pause';
144
+ gameLoop = setInterval(gameUpdate, 1000 / speed);
145
+ }
146
+
147
+ // Game update loop
148
+ function gameUpdate() {
149
+ if (gamePaused) return;
150
+
151
+ // Update direction
152
+ direction = nextDirection;
153
+
154
+ // Move snake
155
+ const head = {x: snake[0].x, y: snake[0].y};
156
+
157
+ switch(direction) {
158
+ case 'up': head.y--; break;
159
+ case 'down': head.y++; break;
160
+ case 'left': head.x--; break;
161
+ case 'right': head.x++; break;
162
+ }
163
+
164
+ // Check wall collision
165
+ if (head.x < 0 || head.x >= tileCount || head.y < 0 || head.y >= tileCount) {
166
+ gameOver();
167
+ return;
168
+ }
169
+
170
+ // Check self collision
171
+ if (snake.some(segment => segment.x === head.x && segment.y === head.y)) {
172
+ gameOver();
173
+ return;
174
+ }
175
+
176
+ // Add new head
177
+ snake.unshift(head);
178
+
179
+ // Check food collision
180
+ if (head.x === food.x && head.y === food.y) {
181
+ score++;
182
+ scoreElement.textContent = score;
183
+
184
+ if (score % 5 === 0) {
185
+ speed += 1;
186
+ clearInterval(gameLoop);
187
+ gameLoop = setInterval(gameUpdate, 1000 / speed);
188
+ }
189
+
190
+ generateFood();
191
+ } else {
192
+ // Remove tail if no food eaten
193
+ snake.pop();
194
+ }
195
+
196
+ // Draw everything
197
+ draw();
198
+ }
199
+
200
+ // Draw game
201
+ function draw() {
202
+ // Clear canvas
203
+ ctx.fillStyle = '#1f2937';
204
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
205
+
206
+ // Draw grid
207
+ ctx.strokeStyle = '#374151';
208
+ ctx.lineWidth = 0.5;
209
+
210
+ for (let i = 0; i < tileCount; i++) {
211
+ ctx.beginPath();
212
+ ctx.moveTo(i * gridSize, 0);
213
+ ctx.lineTo(i * gridSize, canvas.height);
214
+ ctx.stroke();
215
+
216
+ ctx.beginPath();
217
+ ctx.moveTo(0, i * gridSize);
218
+ ctx.lineTo(canvas.width, i * gridSize);
219
+ ctx.stroke();
220
+ }
221
+
222
+ // Draw snake
223
+ snake.forEach((segment, index) => {
224
+ const gradient = ctx.createLinearGradient(
225
+ segment.x * gridSize,
226
+ segment.y * gridSize,
227
+ segment.x * gridSize + gridSize,
228
+ segment.y * gridSize + gridSize
229
+ );
230
+
231
+ if (index === 0) {
232
+ // Head
233
+ gradient.addColorStop(0, '#10b981');
234
+ gradient.addColorStop(1, '#059669');
235
+ } else {
236
+ // Body
237
+ gradient.addColorStop(0, '#34d399');
238
+ gradient.addColorStop(1, '#10b981');
239
+ }
240
+
241
+ ctx.fillStyle = gradient;
242
+ ctx.beginPath();
243
+ ctx.roundRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize, 4);
244
+ ctx.fill();
245
+
246
+ // Eyes on head
247
+ if (index === 0) {
248
+ ctx.fillStyle = 'white';
249
+ const eyeSize = gridSize / 5;
250
+
251
+ // Left eye
252
+ let leftEyeX = segment.x * gridSize + gridSize / 4;
253
+ let leftEyeY = segment.y * gridSize + gridSize / 4;
254
+
255
+ // Right eye
256
+ let rightEyeX = segment.x * gridSize + gridSize * 3/4;
257
+ let rightEyeY = segment.y * gridSize + gridSize / 4;
258
+
259
+ // Adjust eye position based on direction
260
+ if (direction === 'up' || direction === 'down') {
261
+ leftEyeX = segment.x * gridSize + gridSize / 4;
262
+ rightEyeX = segment.x * gridSize + gridSize * 3/4;
263
+
264
+ if (direction === 'up') {
265
+ leftEyeY = segment.y * gridSize + gridSize / 4;
266
+ rightEyeY = segment.y * gridSize + gridSize / 4;
267
+ } else {
268
+ leftEyeY = segment.y * gridSize + gridSize * 3/4;
269
+ rightEyeY = segment.y * gridSize + gridSize * 3/4;
270
+ }
271
+ } else if (direction === 'left' || direction === 'right') {
272
+ leftEyeY = segment.y * gridSize + gridSize / 3;
273
+ rightEyeY = segment.y * gridSize + gridSize * 2/3;
274
+
275
+ if (direction === 'left') {
276
+ leftEyeX = segment.x * gridSize + gridSize / 4;
277
+ rightEyeX = segment.x * gridSize + gridSize / 4;
278
+ } else {
279
+ leftEyeX = segment.x * gridSize + gridSize * 3/4;
280
+ rightEyeX = segment.x * gridSize + gridSize * 3/4;
281
+ }
282
+ }
283
+
284
+ ctx.beginPath();
285
+ ctx.arc(leftEyeX, leftEyeY, eyeSize, 0, Math.PI * 2);
286
+ ctx.fill();
287
+
288
+ ctx.beginPath();
289
+ ctx.arc(rightEyeX, rightEyeY, eyeSize, 0, Math.PI * 2);
290
+ ctx.fill();
291
+ }
292
+ });
293
+
294
+ // Draw food
295
+ ctx.fillStyle = '#ef4444';
296
+ ctx.beginPath();
297
+ ctx.roundRect(food.x * gridSize, food.y * gridSize, gridSize, gridSize, gridSize / 2);
298
+ ctx.fill();
299
+
300
+ // Draw food details
301
+ ctx.fillStyle = 'white';
302
+ ctx.font = `${gridSize / 2}px Arial`;
303
+ ctx.textAlign = 'center';
304
+ ctx.textBaseline = 'middle';
305
+ ctx.fillText('🍎', food.x * gridSize + gridSize / 2, food.y * gridSize + gridSize / 2);
306
+ }
307
+
308
+ // Generate food at random position
309
+ function generateFood() {
310
+ food = {
311
+ x: Math.floor(Math.random() * tileCount),
312
+ y: Math.floor(Math.random() * tileCount)
313
+ };
314
+
315
+ // Make sure food doesn't appear on snake
316
+ while (snake.some(segment => segment.x === food.x && segment.y === food.y)) {
317
+ food = {
318
+ x: Math.floor(Math.random() * tileCount),
319
+ y: Math.floor(Math.random() * tileCount)
320
+ };
321
+ }
322
+ }
323
+
324
+ // Game over
325
+ function gameOver() {
326
+ clearInterval(gameLoop);
327
+ gameRunning = false;
328
+
329
+ if (score > highScore) {
330
+ highScore = score;
331
+ localStorage.setItem('snakeHighScore', highScore);
332
+ highScoreElement.textContent = highScore;
333
+ }
334
+
335
+ finalScoreElement.textContent = score;
336
+ gameOverScreen.classList.remove('hidden');
337
+ startBtn.classList.remove('hidden');
338
+ pauseBtn.classList.add('hidden');
339
+ }
340
+
341
+ // Toggle pause
342
+ function togglePause() {
343
+ if (!gameRunning) return;
344
+
345
+ gamePaused = !gamePaused;
346
+ pauseBtn.textContent = gamePaused ? 'Resume' : 'Pause';
347
+
348
+ if (!gamePaused) {
349
+ gameLoop = setInterval(gameUpdate, 1000 / speed);
350
+ } else {
351
+ clearInterval(gameLoop);
352
+ }
353
+ }
354
+
355
+ // Event listeners
356
+ startBtn.addEventListener('click', initGame);
357
+ pauseBtn.addEventListener('click', togglePause);
358
+ restartBtn.addEventListener('click', initGame);
359
+
360
+ // Keyboard controls
361
+ document.addEventListener('keydown', (e) => {
362
+ if (!gameRunning) return;
363
+
364
+ switch(e.key) {
365
+ case 'ArrowUp':
366
+ if (direction !== 'down') nextDirection = 'up';
367
+ break;
368
+ case 'ArrowDown':
369
+ if (direction !== 'up') nextDirection = 'down';
370
+ break;
371
+ case 'ArrowLeft':
372
+ if (direction !== 'right') nextDirection = 'left';
373
+ break;
374
+ case 'ArrowRight':
375
+ if (direction !== 'left') nextDirection = 'right';
376
+ break;
377
+ case ' ':
378
+ togglePause();
379
+ break;
380
+ }
381
+ });
382
+
383
+ // Mobile controls
384
+ upBtn.addEventListener('click', () => { if (direction !== 'down') nextDirection = 'up'; });
385
+ downBtn.addEventListener('click', () => { if (direction !== 'up') nextDirection = 'down'; });
386
+ leftBtn.addEventListener('click', () => { if (direction !== 'right') nextDirection = 'left'; });
387
+ rightBtn.addEventListener('click', () => { if (direction !== 'left') nextDirection = 'right'; });
388
+
389
+ // Touch controls for mobile
390
+ let touchStartX = 0;
391
+ let touchStartY = 0;
392
+
393
+ canvas.addEventListener('touchstart', (e) => {
394
+ touchStartX = e.changedTouches[0].screenX;
395
+ touchStartY = e.changedTouches[0].screenY;
396
+ }, false);
397
+
398
+ canvas.addEventListener('touchend', (e) => {
399
+ if (!gameRunning) return;
400
+
401
+ const touchEndX = e.changedTouches[0].screenX;
402
+ const touchEndY = e.changedTouches[0].screenY;
403
+
404
+ const dx = touchEndX - touchStartX;
405
+ const dy = touchEndY - touchStartY;
406
+
407
+ // Determine swipe direction
408
+ if (Math.abs(dx) > Math.abs(dy)) {
409
+ // Horizontal swipe
410
+ if (dx > 0 && direction !== 'left') {
411
+ nextDirection = 'right';
412
+ } else if (dx < 0 && direction !== 'right') {
413
+ nextDirection = 'left';
414
+ }
415
+ } else {
416
+ // Vertical swipe
417
+ if (dy > 0 && direction !== 'up') {
418
+ nextDirection = 'down';
419
+ } else if (dy < 0 && direction !== 'down') {
420
+ nextDirection = 'up';
421
+ }
422
+ }
423
+ }, false);
424
+
425
+ // Initial draw
426
+ initGame();
427
+ draw();
428
+ });
429
+ </script>
430
+ <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=faltimiras33/snake-game" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
431
+ </html>
prompts.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ snake game