Skip to content

Commit d94c32c

Browse files
authored
Create lrs.html
1 parent 0e03ea6 commit d94c32c

1 file changed

Lines changed: 141 additions & 0 deletions

File tree

game/lrs.html

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<!DOCTYPE html>
2+
<html lang="zh-CN">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>网页版狼人杀</title>
6+
<style>
7+
.container {
8+
display: grid;
9+
grid-template-columns: 1fr 300px;
10+
gap: 20px;
11+
padding: 20px;
12+
background: #2c3e50;
13+
color: white;
14+
min-height: 100vh;
15+
}
16+
#playerList {
17+
border: 2px solid #34495e;
18+
padding: 15px;
19+
}
20+
.player-card {
21+
background: #34495e;
22+
margin: 10px;
23+
padding: 10px;
24+
border-radius: 5px;
25+
cursor: pointer;
26+
}
27+
button {
28+
background: #3498db;
29+
color: white;
30+
border: none;
31+
padding: 8px 15px;
32+
border-radius: 4px;
33+
margin: 5px;
34+
}
35+
</style>
36+
</head>
37+
<body>
38+
<div class="container">
39+
<div id="playerList"></div>
40+
<div id="actionPanel">
41+
<h3>当前阶段:<span id="phase">夜晚</span></h3>
42+
<div id="skillButtons"></div>
43+
</div>
44+
</div>
45+
46+
<script>
47+
// ================= 游戏核心逻辑 =================
48+
const players = [
49+
{ id: 1, role: '狼人', camp: 'wolf', alive: true },
50+
{ id: 2, role: '平民', camp: 'human', alive: true },
51+
{ id: 3, role: '女巫', camp: 'human', alive: true },
52+
{ id: 4, role: '预言家', camp: 'human', alive: true }
53+
].sort(() => Math.random() - 0.5); // 随机分配角色:ml-citation{ref="2,6" data="citationList"}
54+
55+
let currentPhase = 'night';
56+
let killedPlayer = null;
57+
const witch = { poison: 1, antidote: 1 };
58+
59+
// ================= 界面渲染 =================
60+
function renderPlayers() {
61+
const container = document.getElementById('playerList');
62+
container.innerHTML = players.map(player => `
63+
<div class="player-card" data-id="${player.id}"
64+
onclick="handlePlayerClick(${player.id})"
65+
style="opacity: ${player.alive ? 1 : 0.5}">
66+
<span>玩家 ${player.id}</span>
67+
<span>${player.alive ? '存活' : '死亡'}</span>
68+
</div>
69+
`).join('');
70+
}
71+
72+
function updateActionPanel() {
73+
document.getElementById('phase').textContent =
74+
currentPhase === 'night' ? '夜晚' : '白天';
75+
76+
const skillPanel = document.getElementById('skillButtons');
77+
if (currentPhase === 'night') {
78+
skillPanel.innerHTML = players.find(p => p.role === '狼人')?.alive ?
79+
'<button onclick="endNightPhase()">狼人行动结束</button>' : '';
80+
} else {
81+
skillPanel.innerHTML = '<button onclick="startVoting()">开始投票</button>';
82+
}
83+
}
84+
85+
// ================= 阶段控制 =================
86+
function startNightPhase() {
87+
currentPhase = 'night';
88+
killedPlayer = null;
89+
players.forEach(p => {
90+
if (p.role === '狼人' && p.alive) {
91+
killedPlayer = players[Math.floor(Math.random() * players.length)];
92+
}
93+
});
94+
updateActionPanel();:ml-citation{ref="2,4" data="citationList"}
95+
}
96+
97+
function endNightPhase() {
98+
// 女巫技能触发
99+
if (witch.antidote > 0 && confirm('是否使用解药?')) {
100+
killedPlayer.alive = true;
101+
witch.antidote--;
102+
} else if (witch.poison > 0 && confirm('是否使用毒药?')) {
103+
const target = prompt('输入要毒杀的玩家编号');
104+
players.find(p => p.id == target).alive = false;
105+
witch.poison--;
106+
}
107+
currentPhase = 'day';
108+
renderPlayers();
109+
updateActionPanel();:ml-citation{ref="4,6" data="citationList"}
110+
}
111+
112+
// ================= 事件处理 =================
113+
function handlePlayerClick(playerId) {
114+
if (currentPhase === 'night') return;
115+
const player = players.find(p => p.id === playerId);
116+
if (player.alive) {
117+
player.votes = (player.votes || 0) + 1;
118+
}
119+
}
120+
121+
function startVoting() {
122+
const maxVotes = Math.max(...players.map(p => p.votes || 0));
123+
const votedPlayers = players.filter(p => p.votes === maxVotes);
124+
votedPlayers.forEach(p => p.alive = false);
125+
renderPlayers();
126+
checkGameEnd();:ml-citation{ref="1,6" data="citationList"}
127+
}
128+
129+
function checkGameEnd() {
130+
const wolves = players.filter(p => p.camp === 'wolf' && p.alive);
131+
const humans = players.filter(p => p.camp === 'human' && p.alive);
132+
if (wolves.length === 0) alert('人类阵营胜利!');
133+
if (wolves.length >= humans.length) alert('狼人阵营胜利!');
134+
}
135+
136+
// ================= 初始化 =================
137+
renderPlayers();
138+
startNightPhase();
139+
</script>
140+
</body>
141+
</html>

0 commit comments

Comments
 (0)