[英]How do I get my code to loop back to an input once it has been executed already? (RPG Game)
I'm a beginner at Python and thought it would be fun to code a text-based RPG game.我是 Python 的初学者,我认为编写基于文本的 RPG 游戏会很有趣。 It is by no means efficient, I'm just doing it for the fun of it.
这绝不是有效的,我只是为了好玩。
I want my code to loop back to a specific decision path I have created where you can choose to do different actions.我希望我的代码循环回到我创建的特定决策路径,您可以在其中选择执行不同的操作。 These actions are different subroutines that it calls depending on what you enter.
这些操作是不同的子例程,它会根据您输入的内容调用它们。 However, I can't figure out how to get it to loop back once you have already chosen and completed an action.
但是,一旦您已经选择并完成了一个动作,我无法弄清楚如何让它循环回来。
Here is the code:这是代码:
print("\n~DECISION PATH~\n\n[READ NOTICE BOARD][TALK TO WIZARD][TALK TO BLACKSMITH][TALK TO ARMOURER][VIEW STATS]")
action=input("\nWhat will you do? ")
if action == "Read notice board":
noticeBoard()
elif action == "Talk to wizard":
wizard()
elif action == "Talk to blacksmith":
blacksmith()
elif action == "Talk to armourer":
armourer()
elif action == "View stats":
viewStats()
If somebody could help me out that would be great.如果有人可以帮助我,那就太好了。 Thanks!
谢谢!
Add a while loop with condition = True if you want the user to play it again and again.如果您希望用户一次又一次地播放它,请添加一个带有 condition = True 的 while 循环。 You can add a condition such that exit the game if the user presses a key if you prefer that.
如果您愿意,您可以添加一个条件,以便在用户按下某个键时退出游戏。
print("\n~DECISION PATH~\n\n[READ NOTICE BOARD][TALK TO WIZARD][TALK TO BLACKSMITH][TALK TO ARMOURER][VIEW STATS]")
while(True):
action=input("\nWhat will you do? ")
if action == "Read notice board":
noticeBoard()
elif action == "Talk to wizard":
wizard()
elif action == "Talk to blacksmith":
blacksmith()
elif action == "Talk to armourer":
armourer()
elif action == "View stats":
viewStats()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.