简体   繁体   English

一旦我的代码已经执行,如何让我的代码循环回输入? (角色扮演游戏)

[英]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.

相关问题 用户做出错误选择后,如何使我的游戏链接重新回到开始 - How do i make my game link back to the start once user has made the wrong choice 初学者 python 文字游戏,如何从已使用的列表中删除位置 - beginner python text game, how do I remove a location from a list that has already been used 我怎样才能 go 回到程序已经执行的行? - How can I go back to a line that the program has already executed? 如何检查命令是否已经执行 - How to check if a command has already been executed 为什么我的 python 代码在我的 function “executelogin()” 执行后不继续执行? - Why does my python code not continue execution once my function "executelogin()" has been executed? 如何让python识别出没有输入 - How do I get python to recognize that there has been no input 我如何让用户在Visual Studio Code的基于文本的rpg中保存和加载他们的游戏? - How can I have a user save and load their game in my text-based rpg in Visual Studio Code? JS执行后如何获取网页的HTML代码? - How can I get the HTML code of a webpage after JS has been executed? 如何正确地创建一个条件,一旦条件满足就会退出 while 循环? - How do I properly make a condition that will exit a while loop once a condition has been met? Pygame - 如何检查我的rect是否已被点击? - Pygame - How do I check if my rect has already been clicked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM