python - 你如何在 python 上为基于文本的 rpg 循环?
问题描述
我正在创建一个基于文本的 rpg,我需要弄清楚如何为它做循环,这样我就可以回到他们进展的主要故事图块。我需要将 Map 循环回选项部分。
story = input("What do you do? your choices -> Map, Travel, Exit")
if story == "Exit":
print("you left the game, goodbye" + " " + Name + "!")
import sys
sys.exit()
if story == "Map":
print("Your map shows an abandoned house, Lake, Lab, and abandon asylum.")
解决方案
我不太清楚你的意思,也许是这样的?
while True:
story = input("What do you do? your choices -> Map, Travel, Exit")
if story == "Exit":
print("you left the game, goodbye" + " " + Name + "!")
import sys
sys.exit()
if story == "Map":
print("Your map shows an abandoned house, Lake, Lab, and abandon asylum.")
不过,我个人会做一些改动:
import sys
while True:
story = input("What do you do? your choices are: Map, Travel, Exit").lower()
if story == "exit":
print("you left the game, goodbye {}!".format(Name))
sys.exit()
elif story == "map":
print("Your map shows an abandoned house, lake, lab, and abandoned asylum.")
- 开头导入sys
- 确保输入中的大写无关紧要(节省令人沮丧的游戏体验)
- 修复了最后一个打印语句中的拼写错误
- 您可能希望将输入更改为其他内容,以便它始终有效,无论您使用 python 2 还是 3
推荐阅读
- javascript - 如何在绑定顶点数组对象和缓冲区数据以在渲染时动态绘制时编写通用 webgl 渲染循环?
- c# - 如何以编程方式将 AssemblyInfo.cs 更新为预构建事件 (Visual Studio / msbuild)
- node.js - 我无法使用 sequelize 运行具有多个搜索参数的简单搜索
- javascript - html表单,如何通过传统post和jquery ajax同时向各个服务器发送数据
- azure - 无法在 Azure 门户中保存 JSON 配置文件更新
- javascript - How to autofocus on a specific input field in React (after clicking on another element)?
- flutter - 如何根据 Flutter 中另一个文本字段的值自动设置文本字段的值?
- flutter - 我如何全局处理用户交互?
- r - 插入行以填写 R 中缺少的日期
- angular - 无法在 Windows 10 代理网络系统中安装 angular-cli