-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript1.js
More file actions
135 lines (127 loc) · 4.08 KB
/
Copy pathscript1.js
File metadata and controls
135 lines (127 loc) · 4.08 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
126
127
128
129
130
131
132
133
134
135
const gameData = [
{
bg: "bg1.jpg",
title: "这一天",
desc: "你约到了女神萌庆去爬山,在这之前你们应该先买些食物",
options: [
{ text: "让萌庆卖屁股赊账", change: -10 },
{ text: "请萌庆买食物", change: +10 }
]
},
{
bg: "bg2.jpg",
title: "然后",
desc: "你们到了山底下",
options: [
{ text: "帮萌庆记录上山时刻", change: +10 },
{ text: "帮在外面萌庆导管", change: -10 }
]
},
{
bg: "bg3.jpg",
title: "爬山ing",
desc: "爬了好久好久 萌庆觉得好燥热",
options: [
{ text: "趁机掐萌庆基基", change: -10 },
{ text: "陪萌庆一起爆衣", change: +10 }
]
},
{
bg: "bg4.jpg",
title: "到山顶",
desc: "终于到了山顶 萌庆很高兴 但她好像有点难言之隐",
options: [
{ text: "萌庆想户外露出", change: -10 },
{ text: "萌庆太累了想坐缆车下山", change: +10 }
]
},
{
bg: "bg5.jpg",
title: "晚上",
desc: "累了一天 回到酒店 萌庆饥渴难耐地托掉衣服 她意向",
options: [
{ text: "萌庆太困了", change: +10 },
{ text: "萌庆想被超市", change: -10 }
]
}
];
let currentStage = 0;
let health = 70;
const maxHealth = 200;
const minHealth = 0;
// DOM元素
const choicesEl = document.getElementById("choices");
const resultEl = document.getElementById("result");
const headerEl = document.querySelector(".game-header");
const healthBar = document.getElementById("healthBar");
const healthText = document.getElementById("healthText");
const healthChange = document.getElementById("healthChange");
// 初始化游戏
function initStage() {
const stage = gameData[currentStage];
document.body.style.backgroundImage = `url("${stage.bg}")`;
headerEl.innerHTML = `
<h1>${stage.title}</h1>
<p>${stage.desc}</p>
`;
choicesEl.innerHTML = "";
stage.options.forEach(opt => {
const btn = document.createElement("button");
btn.className = "choice-btn";
btn.textContent = opt.text;
btn.addEventListener("click", () => handleChoice(opt.change));
choicesEl.appendChild(btn);
});
resultEl.textContent = "";
}
// 更新健康值显示
function updateHealth(change) {
health = Math.max(minHealth, Math.min(maxHealth, health + change));
const width = (health / maxHealth) * 100;
healthBar.style.width = `${width}%`;
healthText.textContent = `${health} / ${maxHealth}`;
// 显示变化动画
healthChange.textContent = change > 0 ? `+${change}` : change;
healthChange.className = change > 0 ? "health-change plus" : "health-change minus";
setTimeout(() => {
healthChange.className = "health-change";
}, 1000);
}
// 处理选择
function handleChoice(change) {
updateHealth(change);
currentStage++;
if (currentStage < gameData.length) {
initStage();
} else {
showEnding();
}
}
// 显示最终结算
function showEnding() {
const isSuccess = health > 110;
if (isSuccess) {
document.body.innerHTML = `
<div class="end-page success-page">
<video autoplay muted loop class="success-video">
<source src="success.mp4" type="video/mp4">
</video>
<div class="end-content">
<div>🎉 攻略成功!</div>
<p>最终生命值:${health} / ${maxHealth}</p>
<p>恭喜你抱得美人归!</p>
</div>
</div>
`;
} else {
document.body.innerHTML = `
<div class="end-page" style="background-image: url('bg1.jpg')">
<div>💀 攻略失败</div>
<p>最终生命值:${health} / ${maxHealth}</p>
<p>你的好感度不足,未能攻略萌庆</p>
</div>
`;
}
}
// 一开始就启动第一关
initStage();