bozhong commited on
Commit
771bc87
·
verified ·
1 Parent(s): 3c9f485

undefined - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +421 -19
index.html CHANGED
@@ -1,19 +1,421 @@
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
- <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=bozhong/snake" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>贪吃蛇小游戏</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <style>
9
+ /* 自定义样式 */
10
+ .game-container {
11
+ position: relative;
12
+ width: 100%;
13
+ max-width: 600px;
14
+ margin: 0 auto;
15
+ aspect-ratio: 1/1;
16
+ background-color: #f0f0f0;
17
+ border-radius: 8px;
18
+ overflow: hidden;
19
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
20
+ }
21
+
22
+ .game-board {
23
+ display: grid;
24
+ grid-template-columns: repeat(20, 1fr);
25
+ grid-template-rows: repeat(20, 1fr);
26
+ width: 100%;
27
+ height: 100%;
28
+ }
29
+
30
+ .snake {
31
+ background-color: #4f46e5;
32
+ border-radius: 2px;
33
+ transition: all 0.1s ease;
34
+ }
35
+
36
+ .snake-head {
37
+ background-color: #3730a3;
38
+ border-radius: 4px;
39
+ }
40
+
41
+ .food {
42
+ background-color: #ef4444;
43
+ border-radius: 50%;
44
+ animation: pulse 1s infinite;
45
+ }
46
+
47
+ @keyframes pulse {
48
+ 0% { transform: scale(0.9); }
49
+ 50% { transform: scale(1.1); }
50
+ 100% { transform: scale(0.9); }
51
+ }
52
+
53
+ .game-overlay {
54
+ position: absolute;
55
+ top: 0;
56
+ left: 0;
57
+ right: 0;
58
+ bottom: 0;
59
+ background-color: rgba(0, 0, 0, 0.7);
60
+ display: flex;
61
+ flex-direction: column;
62
+ justify-content: center;
63
+ align-items: center;
64
+ color: white;
65
+ z-index: 10;
66
+ }
67
+
68
+ .control-btn {
69
+ width: 60px;
70
+ height: 60px;
71
+ border-radius: 50%;
72
+ background-color: rgba(255, 255, 255, 0.2);
73
+ display: flex;
74
+ justify-content: center;
75
+ align-items: center;
76
+ font-size: 24px;
77
+ cursor: pointer;
78
+ transition: all 0.2s;
79
+ }
80
+
81
+ .control-btn:hover {
82
+ background-color: rgba(255, 255, 255, 0.3);
83
+ }
84
+
85
+ .control-btn:active {
86
+ transform: scale(0.95);
87
+ }
88
+
89
+ .touch-controls {
90
+ display: none;
91
+ }
92
+
93
+ @media (max-width: 640px) {
94
+ .touch-controls {
95
+ display: grid;
96
+ }
97
+ }
98
+ </style>
99
+ </head>
100
+ <body class="bg-gray-100 min-h-screen flex flex-col items-center justify-start p-4 overflow-hidden">
101
+ <div class="text-center mb-6">
102
+ <h1 class="text-3xl font-bold text-gray-800 mb-2">贪吃蛇小游戏</h1>
103
+ <div class="flex items-center justify-center space-x-4">
104
+ <div class="bg-white rounded-lg px-4 py-2 shadow">
105
+ <span class="text-gray-600">分数: </span>
106
+ <span id="score" class="font-bold text-indigo-600">0</span>
107
+ </div>
108
+ <div class="bg-white rounded-lg px-4 py-2 shadow">
109
+ <span class="text-gray-600">最高分: </span>
110
+ <span id="high-score" class="font-bold text-indigo-600">0</span>
111
+ </div>
112
+ </div>
113
+ </div>
114
+
115
+ <div class="game-container">
116
+ <div id="game-board" class="game-board"></div>
117
+
118
+ <div id="game-overlay" class="game-overlay hidden">
119
+ <h2 class="text-3xl font-bold mb-4">游戏结束!</h2>
120
+ <p class="text-xl mb-6">你的分数: <span id="final-score" class="font-bold">0</span></p>
121
+ <button id="restart-btn" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-6 rounded-lg transition">
122
+ 重新开始
123
+ </button>
124
+ </div>
125
+ </div>
126
+
127
+ <div class="mt-4 flex flex-wrap justify-center gap-4">
128
+ <button id="start-btn" class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-6 rounded-lg transition">
129
+ 开始游戏
130
+ </button>
131
+ <button id="pause-btn" class="bg-yellow-500 hover:bg-yellow-600 text-white font-bold py-2 px-6 rounded-lg transition hidden">
132
+ 暂停
133
+ </button>
134
+ <div class="flex items-center bg-white rounded-lg px-4 py-2 shadow">
135
+ <label for="wall-mode" class="mr-2 text-gray-600">穿墙模式:</label>
136
+ <input type="checkbox" id="wall-mode" class="w-4 h-4 text-indigo-600 rounded">
137
+ </div>
138
+ </div>
139
+
140
+ <!-- 移动端控制按钮 -->
141
+ <div class="touch-controls mt-6 grid grid-cols-3 gap-2">
142
+ <div></div>
143
+ <button id="up-btn" class="control-btn">↑</button>
144
+ <div></div>
145
+ <button id="left-btn" class="control-btn">←</button>
146
+ <div></div>
147
+ <button id="right-btn" class="control-btn">→</button>
148
+ <div></div>
149
+ <button id="down-btn" class="control-btn">↓</button>
150
+ <div></div>
151
+ </div>
152
+
153
+ <div class="mt-8 text-gray-600 text-sm">
154
+ <p>使用键盘方向键或屏幕按钮控制蛇的移动</p>
155
+ </div>
156
+
157
+ <script>
158
+ // 游戏变量
159
+ let snake = [];
160
+ let food = {};
161
+ let direction = 'right';
162
+ let nextDirection = 'right';
163
+ let gameInterval;
164
+ let gameSpeed = 150;
165
+ let score = 0;
166
+ let highScore = localStorage.getItem('snakeHighScore') || 0;
167
+ let isPaused = false;
168
+ let isGameOver = false;
169
+ let wallMode = false;
170
+
171
+ // DOM元素
172
+ const gameBoard = document.getElementById('game-board');
173
+ const scoreDisplay = document.getElementById('score');
174
+ const highScoreDisplay = document.getElementById('high-score');
175
+ const finalScoreDisplay = document.getElementById('final-score');
176
+ const gameOverlay = document.getElementById('game-overlay');
177
+ const startBtn = document.getElementById('start-btn');
178
+ const pauseBtn = document.getElementById('pause-btn');
179
+ const restartBtn = document.getElementById('restart-btn');
180
+
181
+ // 移动端控制按钮
182
+ const upBtn = document.getElementById('up-btn');
183
+ const downBtn = document.getElementById('down-btn');
184
+ const leftBtn = document.getElementById('left-btn');
185
+ const rightBtn = document.getElementById('right-btn');
186
+
187
+ // 初始化游戏
188
+ function initGame() {
189
+ // 清空游戏板
190
+ gameBoard.innerHTML = '';
191
+
192
+ // 初始化蛇
193
+ snake = [
194
+ {x: 10, y: 10},
195
+ {x: 9, y: 10},
196
+ {x: 8, y: 10}
197
+ ];
198
+
199
+ // 初始化方向
200
+ direction = 'right';
201
+ nextDirection = 'right';
202
+
203
+ // 生成食物
204
+ generateFood();
205
+
206
+ // 重置分数
207
+ score = 0;
208
+ scoreDisplay.textContent = score;
209
+ highScoreDisplay.textContent = highScore;
210
+
211
+ // 重置游戏状态
212
+ isPaused = false;
213
+ isGameOver = false;
214
+
215
+ // 隐藏游戏结束界面
216
+ gameOverlay.classList.add('hidden');
217
+
218
+ // 绘制游戏
219
+ drawGame();
220
+ }
221
+
222
+ // 绘制游戏
223
+ function drawGame() {
224
+ // 清空游戏板
225
+ gameBoard.innerHTML = '';
226
+
227
+ // 绘制蛇
228
+ snake.forEach((segment, index) => {
229
+ const snakeElement = document.createElement('div');
230
+ snakeElement.classList.add(index === 0 ? 'snake-head' : 'snake');
231
+ snakeElement.style.gridColumn = segment.x;
232
+ snakeElement.style.gridRow = segment.y;
233
+ gameBoard.appendChild(snakeElement);
234
+ });
235
+
236
+ // 绘制食物
237
+ const foodElement = document.createElement('div');
238
+ foodElement.classList.add('food');
239
+ foodElement.style.gridColumn = food.x;
240
+ foodElement.style.gridRow = food.y;
241
+ gameBoard.appendChild(foodElement);
242
+ }
243
+
244
+ // 生成食物
245
+ function generateFood() {
246
+ // 随机生成食物位置
247
+ food = {
248
+ x: Math.floor(Math.random() * 20) + 1,
249
+ y: Math.floor(Math.random() * 20) + 1
250
+ };
251
+
252
+ // 确保食物不会出现在蛇身上
253
+ for (let segment of snake) {
254
+ if (segment.x === food.x && segment.y === food.y) {
255
+ return generateFood();
256
+ }
257
+ }
258
+ }
259
+
260
+ // 游戏主循环
261
+ function gameLoop() {
262
+ if (isPaused || isGameOver) return;
263
+
264
+ // 更新方向
265
+ direction = nextDirection;
266
+
267
+ // 获取蛇头
268
+ const head = {...snake[0]};
269
+
270
+ // 根据方向移动蛇头
271
+ switch (direction) {
272
+ case 'up':
273
+ head.y -= 1;
274
+ break;
275
+ case 'down':
276
+ head.y += 1;
277
+ break;
278
+ case 'left':
279
+ head.x -= 1;
280
+ break;
281
+ case 'right':
282
+ head.x += 1;
283
+ break;
284
+ }
285
+
286
+ // 检查是否撞墙
287
+ if (!wallMode && (head.x < 1 || head.x > 20 || head.y < 1 || head.y > 20)) {
288
+ gameOver();
289
+ return;
290
+ }
291
+
292
+ // 穿墙处理
293
+ if (wallMode) {
294
+ if (head.x < 1) head.x = 20;
295
+ if (head.x > 20) head.x = 1;
296
+ if (head.y < 1) head.y = 20;
297
+ if (head.y > 20) head.y = 1;
298
+ }
299
+
300
+ // 检查是否撞到自己
301
+ for (let segment of snake) {
302
+ if (segment.x === head.x && segment.y === head.y) {
303
+ gameOver();
304
+ return;
305
+ }
306
+ }
307
+
308
+ // 移动蛇
309
+ snake.unshift(head);
310
+
311
+ // 检查是否吃到食物
312
+ if (head.x === food.x && head.y === food.y) {
313
+ // 增加分数
314
+ score += 10;
315
+ scoreDisplay.textContent = score;
316
+
317
+ // 更新最高分
318
+ if (score > highScore) {
319
+ highScore = score;
320
+ highScoreDisplay.textContent = highScore;
321
+ localStorage.setItem('snakeHighScore', highScore);
322
+ }
323
+
324
+ // 生成新食物
325
+ generateFood();
326
+
327
+ // 加快游戏速度
328
+ if (gameSpeed > 50 && score % 50 === 0) {
329
+ gameSpeed -= 5;
330
+ clearInterval(gameInterval);
331
+ gameInterval = setInterval(gameLoop, gameSpeed);
332
+ }
333
+ } else {
334
+ // 如果没有吃到食物,移除蛇尾
335
+ snake.pop();
336
+ }
337
+
338
+ // 重新绘制游戏
339
+ drawGame();
340
+ }
341
+
342
+ // 游戏结束
343
+ function gameOver() {
344
+ clearInterval(gameInterval);
345
+ isGameOver = true;
346
+ finalScoreDisplay.textContent = score;
347
+ gameOverlay.classList.remove('hidden');
348
+ }
349
+
350
+ // 开始游戏
351
+ function startGame() {
352
+ initGame();
353
+ gameInterval = setInterval(gameLoop, gameSpeed);
354
+ startBtn.classList.add('hidden');
355
+ pauseBtn.classList.remove('hidden');
356
+ }
357
+
358
+ // 暂停游戏
359
+ function togglePause() {
360
+ isPaused = !isPaused;
361
+ pauseBtn.textContent = isPaused ? '继续' : '暂停';
362
+ }
363
+
364
+ // 事件监听器
365
+ startBtn.addEventListener('click', startGame);
366
+ pauseBtn.addEventListener('click', togglePause);
367
+ restartBtn.addEventListener('click', startGame);
368
+
369
+ // 键盘控制
370
+ document.addEventListener('keydown', (e) => {
371
+ // 阻止方向键默认行为
372
+ if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', ' '].includes(e.key)) {
373
+ e.preventDefault();
374
+ }
375
+
376
+ switch (e.key) {
377
+ case 'ArrowUp':
378
+ if (direction !== 'down') nextDirection = 'up';
379
+ break;
380
+ case 'ArrowDown':
381
+ if (direction !== 'up') nextDirection = 'down';
382
+ break;
383
+ case 'ArrowLeft':
384
+ if (direction !== 'right') nextDirection = 'left';
385
+ break;
386
+ case 'ArrowRight':
387
+ if (direction !== 'left') nextDirection = 'right';
388
+ break;
389
+ case ' ':
390
+ if (!isGameOver) togglePause();
391
+ break;
392
+ }
393
+ });
394
+
395
+ // 穿墙模式切换
396
+ document.getElementById('wall-mode').addEventListener('change', (e) => {
397
+ wallMode = e.target.checked;
398
+ });
399
+
400
+ // 移动端控制
401
+ upBtn.addEventListener('click', () => {
402
+ if (direction !== 'down') nextDirection = 'up';
403
+ });
404
+
405
+ downBtn.addEventListener('click', () => {
406
+ if (direction !== 'up') nextDirection = 'down';
407
+ });
408
+
409
+ leftBtn.addEventListener('click', () => {
410
+ if (direction !== 'right') nextDirection = 'left';
411
+ });
412
+
413
+ rightBtn.addEventListener('click', () => {
414
+ if (direction !== 'left') nextDirection = 'right';
415
+ });
416
+
417
+ // 初始化显示
418
+ highScoreDisplay.textContent = highScore;
419
+ </script>
420
+ <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=bozhong/awesome-about-me" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p><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=bozhong/snake" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
421
+ </html>