如何在python上基于文本的rpg循环?

时间:2018-10-22 22:42:45

标签: python loops

我正在创建一个基于文本的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.")

1 个答案:

答案 0 :(得分:0)

我不太确定你的意思,也许是这样的东西?

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,您都可能希望将输入更改为其他内容,这样它始终可以正常工作