你如何在python上为基于文本的RPG做循环?



我正在创建一个基于文本的RPG,我需要弄清楚如何为它做循环,这样我就可以回到他们前进的主要故事图块。我需要循环映射回选项部分。

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.")
  • 在开始时导入系统
  • 确保大写字母在输入中无关紧要(节省令人沮丧的游戏体验(
  • 修复了最后一个打印语句中的拼写错误
  • 您可能希望将输入更改为其他内容,以便它始终有效,无论您使用的是python 2还是3

最新更新