bozhong commited on
Commit
2dcd3be
·
verified ·
1 Parent(s): 771bc87

增加排行榜TOP,表明 - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +36 -43
index.html CHANGED
@@ -86,15 +86,6 @@
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">
@@ -137,20 +128,16 @@
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
 
@@ -178,12 +165,6 @@
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
  // 清空游戏板
@@ -345,6 +326,7 @@
345
  isGameOver = true;
346
  finalScoreDisplay.textContent = score;
347
  gameOverlay.classList.remove('hidden');
 
348
  }
349
 
350
  // 开始游戏
@@ -397,25 +379,36 @@
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>
 
86
  transform: scale(0.95);
87
  }
88
 
 
 
 
 
 
 
 
 
 
89
  </style>
90
  </head>
91
  <body class="bg-gray-100 min-h-screen flex flex-col items-center justify-start p-4 overflow-hidden">
 
128
  </div>
129
  </div>
130
 
131
+ <div class="mt-8 w-full max-w-md">
132
+ <div class="bg-white rounded-lg shadow p-4">
133
+ <h3 class="text-xl font-bold text-gray-800 mb-4">排行榜 TOP 5</h3>
134
+ <div id="leaderboard" class="space-y-2">
135
+ <!-- Leaderboard items will be added here by JavaScript -->
136
+ </div>
137
+ </div>
 
 
 
 
138
  </div>
139
+
140
+ <div class="mt-4 text-gray-600 text-sm">
141
  <p>使用键盘方向键或屏幕按钮控制蛇的移动</p>
142
  </div>
143
 
 
165
  const pauseBtn = document.getElementById('pause-btn');
166
  const restartBtn = document.getElementById('restart-btn');
167
 
 
 
 
 
 
 
168
  // 初始化游戏
169
  function initGame() {
170
  // 清空游戏板
 
326
  isGameOver = true;
327
  finalScoreDisplay.textContent = score;
328
  gameOverlay.classList.remove('hidden');
329
+ updateLeaderboard();
330
  }
331
 
332
  // 开始游戏
 
379
  wallMode = e.target.checked;
380
  });
381
 
382
+ // 排行榜功能
383
+ let leaderboard = JSON.parse(localStorage.getItem('snakeLeaderboard')) || [];
 
 
 
 
 
 
384
 
385
+ function updateLeaderboard() {
386
+ // 添加当前分数到排行榜
387
+ leaderboard.push(score);
388
+ // 排序并保留前5名
389
+ leaderboard.sort((a, b) => b - a);
390
+ leaderboard = leaderboard.slice(0, 5);
391
+ // 保存到本地存储
392
+ localStorage.setItem('snakeLeaderboard', JSON.stringify(leaderboard));
393
+
394
+ // 更新显示
395
+ const leaderboardElement = document.getElementById('leaderboard');
396
+ leaderboardElement.innerHTML = '';
397
+
398
+ leaderboard.forEach((score, index) => {
399
+ const item = document.createElement('div');
400
+ item.className = 'flex justify-between items-center bg-gray-50 p-2 rounded';
401
+ item.innerHTML = `
402
+ <span class="font-medium">${index + 1}. ${score}</span>
403
+ <span class="text-xs text-gray-500">${new Date().toLocaleDateString()}</span>
404
+ `;
405
+ leaderboardElement.appendChild(item);
406
+ });
407
+ }
408
 
409
  // 初始化显示
410
  highScoreDisplay.textContent = highScore;
411
+ updateLeaderboard();
412
  </script>
413
  <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>
414
  </html>