簡體   English   中英

你如何在 python 上為基於文本的 rpg 循環?

[英]How do you do loops for a text based rpg on python?

我正在創建一個基於文本的 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM