This repository was archived by the owner on Oct 8, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
125 lines (117 loc) · 3.87 KB
/
Copy pathindex.html
File metadata and controls
125 lines (117 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>贪吃蛇游戏</title>
<style>
/* 全局重置 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #0f0f23;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
font-family: Arial, sans-serif;
}
/* 游戏容器(居中,宽度自适应) */
.game-container {
width: min(90vw, 90vh);
max-width: 1000px;
}
/* 分数面板 */
.score-panel {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
padding: 8px 0;
font-size: clamp(16px, 2vw, 32px);
gap: 8px;
}
/* 静音按钮(TASK-003) */
.icon-btn {
background: transparent;
border: none;
font-size: clamp(20px, 3vw, 32px);
cursor: pointer;
padding: 4px;
}
#score { color: #FFD700; }
#highScore { color: #C0C0C0; }
/* 游戏画布(宽度跟随容器,高度自动保持比例) */
#gameCanvas {
display: block;
width: 100%;
height: auto;
border: 2px solid #16213e;
border-radius: 4px;
touch-action: none; /* 禁止触摸滚动/缩放(TASK-002) */
}
/* 虚拟方向键(TASK-002)— 默认隐藏,< 768px 显示 */
.dpad-container {
display: none;
flex-direction: column;
align-items: center;
margin-top: 16px;
gap: 4px;
}
.dpad-middle {
display: flex;
align-items: center;
gap: 4px;
}
.dpad-btn {
width: clamp(48px, 12vw, 64px);
height: clamp(48px, 12vw, 64px);
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 8px;
color: #ffffff;
font-size: clamp(18px, 4vw, 24px);
cursor: pointer;
touch-action: manipulation;
user-select: none;
-webkit-user-select: none;
}
.dpad-btn:active {
background: rgba(255, 255, 255, 0.3);
}
.dpad-center {
width: clamp(48px, 12vw, 64px);
height: clamp(48px, 12vw, 64px);
}
@media (max-width: 767px) {
.dpad-container { display: flex; }
}
</style>
</head>
<body>
<div class="game-container">
<!-- 分数面板 -->
<div class="score-panel">
<span id="score">分数: 0</span>
<span id="highScore">最高分: 0</span>
<button id="muteBtn" class="icon-btn" aria-label="静音切换">🔊</button>
</div>
<!-- 游戏画布(动态尺寸,由JS计算) -->
<canvas id="gameCanvas" width="400" height="400"></canvas>
<!-- 虚拟方向键(TASK-002)— 仅 < 768px 显示 -->
<div id="dpad" class="dpad-container">
<button class="dpad-btn dpad-up" data-dir="up" aria-label="上">▲</button>
<div class="dpad-middle">
<button class="dpad-btn dpad-left" data-dir="left" aria-label="左">◀</button>
<div class="dpad-center"></div>
<button class="dpad-btn dpad-right" data-dir="right" aria-label="右">▶</button>
</div>
<button class="dpad-btn dpad-down" data-dir="down" aria-label="下">▼</button>
</div>
</div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>