blackeeee commited on
Commit
ef422a7
·
verified ·
1 Parent(s): 7992333

сделай змейку

Browse files
Files changed (2) hide show
  1. README.md +7 -4
  2. index.html +334 -18
README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: Slithering Snake Saga
3
- emoji:
4
- colorFrom: green
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: Slithering Snake Saga 🐍
3
+ colorFrom: gray
 
4
  colorTo: pink
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://deepsite.hf.co).
index.html CHANGED
@@ -1,19 +1,335 @@
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>Slithering Snake Saga</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <style>
9
+ body {
10
+ overflow: hidden;
11
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
12
+ }
13
+ canvas {
14
+ display: block;
15
+ margin: 0 auto;
16
+ background-color: #111827;
17
+ border-radius: 0.5rem;
18
+ box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2);
19
+ }
20
+ .game-container {
21
+ position: relative;
22
+ }
23
+ .controls {
24
+ position: absolute;
25
+ bottom: 20px;
26
+ width: 100%;
27
+ display: none;
28
+ justify-content: center;
29
+ gap: 10px;
30
+ }
31
+ @media (max-width: 768px) {
32
+ .controls {
33
+ display: flex;
34
+ }
35
+ }
36
+ </style>
37
+ </head>
38
+ <body class="bg-gray-900 text-white min-h-screen flex flex-col items-center justify-center p-4">
39
+ <div class="text-center mb-6">
40
+ <h1 class="text-4xl font-bold text-green-400 mb-2">Slithering Snake Saga</h1>
41
+ <p class="text-gray-300">Use arrow keys or tap buttons to control the snake</p>
42
+ </div>
43
+
44
+ <div class="game-container">
45
+ <canvas id="gameCanvas" width="400" height="400"></canvas>
46
+ <div class="controls">
47
+ <button id="upBtn" class="bg-green-500 hover:bg-green-600 text-white font-bold py-4 px-6 rounded-full">
48
+
49
+ </button>
50
+ <div class="flex flex-col gap-2">
51
+ <button id="leftBtn" class="bg-green-500 hover:bg-green-600 text-white font-bold py-4 px-6 rounded-full">
52
+
53
+ </button>
54
+ <button id="rightBtn" class="bg-green-500 hover:bg-green-600 text-white font-bold py-4 px-6 rounded-full">
55
+
56
+ </button>
57
+ </div>
58
+ <button id="downBtn" class="bg-green-500 hover:bg-green-600 text-white font-bold py-4 px-6 rounded-full">
59
+
60
+ </button>
61
+ </div>
62
+ </div>
63
+
64
+ <div class="mt-6 flex gap-4 items-center">
65
+ <div class="bg-gray-800 p-3 rounded-lg">
66
+ <span class="text-green-400 font-bold">Score: </span>
67
+ <span id="score" class="text-white">0</span>
68
+ </div>
69
+ <button id="startBtn" class="bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-6 rounded-lg">
70
+ Start Game
71
+ </button>
72
+ <button id="resetBtn" class="bg-gray-700 hover:bg-gray-600 text-white font-bold py-2 px-6 rounded-lg">
73
+ Reset
74
+ </button>
75
+ </div>
76
+
77
+ <script>
78
+ document.addEventListener('DOMContentLoaded', () => {
79
+ const canvas = document.getElementById('gameCanvas');
80
+ const ctx = canvas.getContext('2d');
81
+ const scoreElement = document.getElementById('score');
82
+ const startBtn = document.getElementById('startBtn');
83
+ const resetBtn = document.getElementById('resetBtn');
84
+ const upBtn = document.getElementById('upBtn');
85
+ const downBtn = document.getElementById('downBtn');
86
+ const leftBtn = document.getElementById('leftBtn');
87
+ const rightBtn = document.getElementById('rightBtn');
88
+
89
+ // Game variables
90
+ let snake = [];
91
+ let food = {};
92
+ let direction = 'right';
93
+ let nextDirection = 'right';
94
+ let gameSpeed = 150;
95
+ let score = 0;
96
+ let gameInterval;
97
+ let gameRunning = false;
98
+ const gridSize = 20;
99
+ const tileCount = canvas.width / gridSize;
100
+
101
+ // Initialize game
102
+ function initGame() {
103
+ snake = [];
104
+ for (let i = 3; i >= 0; i--) {
105
+ snake.push({ x: i * gridSize, y: 0 });
106
+ }
107
+
108
+ generateFood();
109
+ score = 0;
110
+ scoreElement.textContent = score;
111
+ direction = 'right';
112
+ nextDirection = 'right';
113
+
114
+ if (gameRunning) {
115
+ clearInterval(gameInterval);
116
+ gameInterval = setInterval(gameLoop, gameSpeed);
117
+ }
118
+
119
+ drawGame();
120
+ }
121
+
122
+ // Generate food at random position
123
+ function generateFood() {
124
+ food = {
125
+ x: Math.floor(Math.random() * tileCount) * gridSize,
126
+ y: Math.floor(Math.random() * tileCount) * gridSize
127
+ };
128
+
129
+ // Make sure food doesn't spawn on snake
130
+ for (let segment of snake) {
131
+ if (segment.x === food.x && segment.y === food.y) {
132
+ return generateFood();
133
+ }
134
+ }
135
+ }
136
+
137
+ // Main game loop
138
+ function gameLoop() {
139
+ moveSnake();
140
+ checkCollision();
141
+ drawGame();
142
+ }
143
+
144
+ // Move the snake
145
+ function moveSnake() {
146
+ direction = nextDirection;
147
+
148
+ // Calculate new head position
149
+ const head = { x: snake[0].x, y: snake[0].y };
150
+
151
+ switch (direction) {
152
+ case 'up':
153
+ head.y -= gridSize;
154
+ break;
155
+ case 'down':
156
+ head.y += gridSize;
157
+ break;
158
+ case 'left':
159
+ head.x -= gridSize;
160
+ break;
161
+ case 'right':
162
+ head.x += gridSize;
163
+ break;
164
+ }
165
+
166
+ // Add new head
167
+ snake.unshift(head);
168
+
169
+ // Check if snake ate food
170
+ if (head.x === food.x && head.y === food.y) {
171
+ score++;
172
+ scoreElement.textContent = score;
173
+ generateFood();
174
+
175
+ // Increase speed every 5 points
176
+ if (score % 5 === 0) {
177
+ gameSpeed = Math.max(50, gameSpeed - 10);
178
+ clearInterval(gameInterval);
179
+ gameInterval = setInterval(gameLoop, gameSpeed);
180
+ }
181
+ } else {
182
+ // Remove tail if no food eaten
183
+ snake.pop();
184
+ }
185
+ }
186
+
187
+ // Check for collisions
188
+ function checkCollision() {
189
+ const head = snake[0];
190
+
191
+ // Wall collision
192
+ if (
193
+ head.x < 0 || head.x >= canvas.width ||
194
+ head.y < 0 || head.y >= canvas.height
195
+ ) {
196
+ gameOver();
197
+ }
198
+
199
+ // Self collision
200
+ for (let i = 1; i < snake.length; i++) {
201
+ if (head.x === snake[i].x && head.y === snake[i].y) {
202
+ gameOver();
203
+ }
204
+ }
205
+ }
206
+
207
+ // Game over
208
+ function gameOver() {
209
+ clearInterval(gameInterval);
210
+ gameRunning = false;
211
+ startBtn.textContent = 'Restart Game';
212
+ alert(`Game Over! Your score: ${score}`);
213
+ }
214
+
215
+ // Draw game elements
216
+ function drawGame() {
217
+ // Clear canvas
218
+ ctx.fillStyle = '#111827';
219
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
220
+
221
+ // Draw snake
222
+ snake.forEach((segment, index) => {
223
+ const gradient = ctx.createLinearGradient(segment.x, segment.y, segment.x + gridSize, segment.y + gridSize);
224
+
225
+ if (index === 0) {
226
+ // Head - brighter green
227
+ gradient.addColorStop(0, '#4ade80');
228
+ gradient.addColorStop(1, '#22c55e');
229
+ } else {
230
+ // Body - darker green
231
+ gradient.addColorStop(0, '#16a34a');
232
+ gradient.addColorStop(1, '#15803d');
233
+ }
234
+
235
+ ctx.fillStyle = gradient;
236
+ ctx.fillRect(segment.x, segment.y, gridSize - 1, gridSize - 1);
237
+
238
+ // Add eyes to head
239
+ if (index === 0) {
240
+ ctx.fillStyle = 'white';
241
+ // Right eye
242
+ if (direction === 'right') {
243
+ ctx.fillRect(segment.x + 12, segment.y + 5, 3, 3);
244
+ ctx.fillRect(segment.x + 12, segment.y + 12, 3, 3);
245
+ }
246
+ // Left eye
247
+ else if (direction === 'left') {
248
+ ctx.fillRect(segment.x + 5, segment.y + 5, 3, 3);
249
+ ctx.fillRect(segment.x + 5, segment.y + 12, 3, 3);
250
+ }
251
+ // Up eye
252
+ else if (direction === 'up') {
253
+ ctx.fillRect(segment.x + 5, segment.y + 5, 3, 3);
254
+ ctx.fillRect(segment.x + 12, segment.y + 5, 3, 3);
255
+ }
256
+ // Down eye
257
+ else if (direction === 'down') {
258
+ ctx.fillRect(segment.x + 5, segment.y + 12, 3, 3);
259
+ ctx.fillRect(segment.x + 12, segment.y + 12, 3, 3);
260
+ }
261
+ }
262
+ });
263
+
264
+ // Draw food
265
+ const foodGradient = ctx.createRadialGradient(
266
+ food.x + gridSize/2, food.y + gridSize/2, 0,
267
+ food.x + gridSize/2, food.y + gridSize/2, gridSize/2
268
+ );
269
+ foodGradient.addColorStop(0, '#ef4444');
270
+ foodGradient.addColorStop(1, '#dc2626');
271
+ ctx.fillStyle = foodGradient;
272
+ ctx.beginPath();
273
+ ctx.arc(food.x + gridSize/2, food.y + gridSize/2, gridSize/2 - 1, 0, Math.PI * 2);
274
+ ctx.fill();
275
+ }
276
+
277
+ // Event listeners
278
+ startBtn.addEventListener('click', () => {
279
+ if (!gameRunning) {
280
+ gameRunning = true;
281
+ startBtn.textContent = 'Pause';
282
+ initGame();
283
+ gameInterval = setInterval(gameLoop, gameSpeed);
284
+ } else {
285
+ gameRunning = false;
286
+ clearInterval(gameInterval);
287
+ startBtn.textContent = 'Resume';
288
+ }
289
+ });
290
+
291
+ resetBtn.addEventListener('click', () => {
292
+ clearInterval(gameInterval);
293
+ gameRunning = false;
294
+ startBtn.textContent = 'Start Game';
295
+ initGame();
296
+ });
297
+
298
+ // Keyboard controls
299
+ document.addEventListener('keydown', (e) => {
300
+ switch (e.key) {
301
+ case 'ArrowUp':
302
+ if (direction !== 'down') nextDirection = 'up';
303
+ break;
304
+ case 'ArrowDown':
305
+ if (direction !== 'up') nextDirection = 'down';
306
+ break;
307
+ case 'ArrowLeft':
308
+ if (direction !== 'right') nextDirection = 'left';
309
+ break;
310
+ case 'ArrowRight':
311
+ if (direction !== 'left') nextDirection = 'right';
312
+ break;
313
+ }
314
+ });
315
+
316
+ // Touch controls
317
+ upBtn.addEventListener('click', () => {
318
+ if (direction !== 'down') nextDirection = 'up';
319
+ });
320
+ downBtn.addEventListener('click', () => {
321
+ if (direction !== 'up') nextDirection = 'down';
322
+ });
323
+ leftBtn.addEventListener('click', () => {
324
+ if (direction !== 'right') nextDirection = 'left';
325
+ });
326
+ rightBtn.addEventListener('click', () => {
327
+ if (direction !== 'left') nextDirection = 'right';
328
+ });
329
+
330
+ // Initialize game state
331
+ initGame();
332
+ });
333
+ </script>
334
+ </body>
335
  </html>