import time
import random
def print_slow(text, delay=0.03):
"""缓慢打印文本,增强沉浸感"""
for char in text:
print(char, end='', flush=True)
time.sleep(delay)
print()
def game_intro():
"""游戏介绍"""
print_slow("\n=== 神秘森林冒险 ===")
print_slow("\n你从一片漆黑中醒来,发现自己身处一片陌生的森林边缘。")
print_slow("周围树木参天,雾气弥漫,隐约能听到远处传来奇怪的声音。")
print_slow("你的记忆一片空白,只知道必须找到离开这里的路。")
print_slow("口袋里只有一把小刀和一个快没电的手电筒。\n")
name = input("请输入你的名字: ")
print_slow(f"\n欢迎,{name}。你的冒险即将开始...\n")
return name
def make_choice(choices):
"""处理玩家选择"""
while True:
for i, choice in enumerate(choices, 1):
print_slow(f"{i}. {choice}")
try:
selection = int(input("\n请选择 (1-{}): ".format(len(choices))))
if 1 <= selection <= len(choices):
return selection - 1 # 返回索引
else:
print_slow(f"请输入1到{len(choices)}之间的数字!")
except ValueError:
print_slow("请输入有效的数字!")
def forest_clearing():
"""森林空地场景"""
print_slow("\n你穿过茂密的树林,来到一片小小的空地。")
print_slow("空地中央有一棵古老的大树,树干上似乎有什么东西。")
print_slow("空地的另一边有两条路:一条向左通往幽暗的山谷,一条向右通往一座小桥。")
choices = [
"检查古老的大树",
"向左通往幽暗的山谷",
"向右通往小桥"
]
choice = make_choice(choices)
if choice == 0:
print_slow("\n你走近古老的大树,发现树干上有一个小盒子。")
print_slow("盒子没有上锁,你打开它,发现里面有一张破旧的地图和一些干粮。")
print_slow("你收起了地图和干粮,感觉这会很有用。")
print_slow("地图上标记着一个方向,似乎指向森林的出口。")
return "found_map"
elif choice == 1:
print_slow("\n你决定前往幽暗的山谷。")
print_slow("山谷里越来越暗,手电筒的光芒也越来越弱...")
return "valley"
else:
print_slow("\n你走向小桥,桥看起来有些摇晃,但似乎还能通过。")
return "bridge"
def cross_bridge():
"""过桥场景"""
print_slow("\n你站在小桥上,桥下面是湍急的河流。")
print_slow("突然,桥身开始剧烈摇晃,几块木板松动掉落。")
choices = [
"快速跑过去",
"小心翼翼地慢慢走",
"返回刚才的空地"
]
choice = make_choice(choices)
if choice == 0:
print_slow("\n你决定快速跑过去!")
if random.random() > 0.3: # 70%成功率
print_slow("你成功了!虽然有些惊险,但你安全到达了对岸。")
print_slow("对岸有一条明显的小路,似乎有人走过。")
return "path"
else:
print_slow("快跑中,一块木板突然断裂,你失足落入湍急的河流...")
return "game_over"
elif choice == 1:
print_slow("\n你小心翼翼地慢慢走。")
print_slow("每一步都很谨慎,虽然花费了些时间,但你安全到达了对岸。")
print_slow("对岸有一条明显的小路,似乎有人走过。")
return "path"
else:
print_slow("\n你决定返回空地再做打算。")
return "clearing"
def dark_valley():
"""幽暗山谷场景"""
print_slow("\n山谷里异常幽暗,手电筒只能照亮前方几米的地方。")
print_slow("你听到身后传来奇怪的脚步声,似乎有什么东西在跟着你。")
choices = [
"加快脚步,试图甩掉它",
"停下来,转身查看",
"寻找地方躲藏起来"
]
choice = make_choice(choices)
if choice == 0:
print_slow("\n你加快了脚步,心跳加速。")
print_slow("身后的声音也加快了,越来越近...")
if random.random() > 0.5: # 50%成功率
print_slow("你看到前方有一处亮光,奋力跑去,发现是一个山洞。")
print_slow("你冲进山洞,然后用石头堵住了入口。")
return "cave"
else:
print_slow("你感到被什么东西抓住了脚踝,摔倒在地...")
return "game_over"
elif choice == 1:
print_slow("\n你鼓起勇气转身查看,手电筒照过去...")
print_slow("原来是一只受惊的小鹿,看到你后飞快地跑开了。")
print_slow("你松了一口气,继续向前走,发现前方有一个山洞。")
return "cave"
else:
print_slow("\n你迅速躲到一块大石头后面。")
print_slow("过了一会儿,你看到一只狐狸从你面前走过,原来只是它。")
print_slow("你从躲藏处出来,继续前进,发现前方有一个山洞。")
return "cave"
def cave_interior(has_map):
"""山洞内部场景"""
print_slow("\n你进入了山洞,里面意外地宽敞。")
print_slow("洞壁上有一些奇怪的符号,角落里似乎有什么东西在发光。")
choices = [
"研究洞壁上的符号",
"查看角落里发光的东西",
"离开山洞,回到山谷"
]
choice = make_choice(choices)
if choice == 0:
print_slow("\n你仔细研究洞壁上的符号。")
if has_map:
print_slow("这些符号和你找到的地图上的标记很相似!")
print_slow("你破解了符号的含义,发现它们指示了一条秘密通道。")
print_slow("你沿着通道前进,发现了一个出口!")
return "escape"
else:
print_slow("这些符号看起来很古老,但你无法理解它们的含义。")
print_slow("研究了一会儿,你决定去看看角落里的东西。")
return "cave_item"
elif choice == 1:
print_slow("\n你走向角落,发现发光的是一堆篝火和一个背包。")
print_slow("背包里有一些食物、水和一张地图!")
print_slow("地图上标记着森林的出口位置。")
return "found_map_in_cave"
else:
print_slow("\n你决定离开山洞,回到山谷。")
return "valley"
def forest_path(has_map):
"""森林小路场景"""
print_slow("\n你沿着小路前进,周围的树木渐渐稀疏。")
print_slow("小路分岔成两条:一条看起来平坦但很长,另一条陡峭但似乎更近。")
if has_map:
print_slow("根据你找到的地图,陡峭的那条路确实能更快到达出口。")
choices = [
"走平坦但较长的路",
"走陡峭但较短的路"
]
else:
choices = [
"走平坦但较长的路",
"走陡峭但较短的路",
"停下来,尝试辨别方向"
]
choice = make_choice(choices)
if choice == 0:
print_slow("\n你选择了平坦但较长的路。")
print_slow("虽然走了很久,但一路平安。")
print_slow("终于,你看到了森林的边缘和一条公路!")
return "escape"
elif choice == 1:
print_slow("\n你选择了陡峭但较短的路。")
if random.random() > 0.2: # 80%成功率
print_slow("路虽然难走,但你成功克服了困难。")
print_slow("很快,你看到了森林的边缘和一条公路!")
return "escape"
else:
print_slow("在攀爬过程中,你脚下一滑,滚下了山坡...")
return "game_over"
else:
print_slow("\n你停下来辨别方向,但周围的环境让你更加困惑。")
print_slow("天色渐暗,你决定还是选择一条路前进。")
return "path"
def game_over(name):
"""游戏结束场景"""
print_slow("\n=== 游戏结束 ===")
print_slow(f"很遗憾,{name},你的冒险在这里结束了。")
choices = [
"再试一次",
"退出游戏"
]
choice = make_choice(choices)
return "restart" if choice == 0 else "quit"
def escape_success(name):
"""成功逃脱场景"""
print_slow("\n=== 恭喜你! ===")
print_slow(f"太棒了,{name}!你成功逃出了神秘森林!")
print_slow("在森林边缘,你遇到了一位猎人,他带你回到了村庄。")
print_slow("虽然你的记忆还没有完全恢复,但至少你安全了。")
print_slow("也许有一天,你会回到这里,解开更多的秘密...")
choices = [
"再玩一次",
"退出游戏"
]
choice = make_choice(choices)
return "restart" if choice == 0 else "quit"
def main_game():
"""游戏主函数"""
name = game_intro()
has_map = False
current_scene = "clearing"
while True:
if current_scene == "clearing":
result = forest_clearing()
if result == "found_map":
has_map = True
current_scene = "clearing"
else:
current_scene = result
elif current_scene == "bridge":
current_scene = cross_bridge()
elif current_scene == "valley":
current_scene = dark_valley()
elif current_scene == "cave":
result = cave_interior(has_map)
if result == "found_map_in_cave":
has_map = True
current_scene = "cave"
else:
current_scene = result
elif current_scene == "path":
current_scene = forest_path(has_map)
elif current_scene == "game_over":
result = game_over(name)
if result == "restart":
return True # 重新开始游戏
else:
break # 退出游戏
elif current_scene == "escape":
result = escape_success(name)
if result == "restart":
return True # 重新开始游戏
else:
break # 退出游戏
else:
print_slow("发生错误,游戏结束。")
break
if __name__ == "__main__":
print_slow("欢迎来到神秘森林冒险!")
while True:
restart = main_game()
if not restart:
print_slow("\n感谢游玩!再见!")
break