-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path文字游戏.html
More file actions
89 lines (82 loc) · 3.21 KB
/
Copy path文字游戏.html
File metadata and controls
89 lines (82 loc) · 3.21 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
<!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>
body {
text-align: center;
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
h1 {
font-size: 24px;
color: #333;
}
p {
color: #666;
margin-top: 20px;
}
.option-btn {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
margin-top: 10px;
font-size: 16px;
cursor: pointer;
}
.option-btn:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h1>文字冒险游戏</h1>
<p>你走进了一座黑暗的洞穴,前方分出三条道路。你会选择哪个道路探索?</p>
<button class="option-btn" onclick="choosePath('left')">左边的道路</button>
<button class="option-btn" onclick="choosePath('middle')">中间的道路</button>
<button class="option-btn" onclick="choosePath('right')">右边的道路</button>
<script>
var storyText = document.querySelector("p");
function choosePath(path) {
var randomNum = Math.random();
if (path === 'left') {
if (randomNum < 0.3) {
storyText.textContent = "你走进了一个废弃的宝藏库,获得了一大袋金币!";
} else if (randomNum < 0.6) {
storyText.textContent = "你遭遇了一群恶龙,勇敢地与它们战斗,并成功击退了它们!";
} else {
storyText.textContent = "你迷失在了洞穴中,找不到回去的路。";
}
} else if (path === 'middle') {
if (randomNum < 0.5) {
storyText.textContent = "你掉入了陷阱,但幸运地逃脱了!";
} else {
storyText.textContent = "你发现了一位友善的精灵,它帮助你找到了回家的路。";
}
} else if (path === 'right') {
if (randomNum < 0.7) {
storyText.textContent = "你遇到了一只可爱的小狗,它成为了你的好朋友!";
} else {
storyText.textContent = "你探索了一段时间后,突然不小心摔倒了,但没有受伤。";
}
}
updateOptions();
}
function updateOptions() {
var options = document.getElementsByClassName("option-btn");
for (var i = 0; i < options.length; i++) {
options[i].disabled = true;
}
setTimeout(function() {
for (var i = 0; i < options.length; i++) {
options[i].disabled = false;
}
storyText.textContent = "你继续向前走,在面前出现了新的道路选择。";
}, 2000);
}
</script>
</body>
</html>