一旦用户做出错误的选择,我如何让我的游戏链接回到开始

真正的福西特

我目前正在创建一个基于文本的冒险游戏,一旦用户死亡或选择了错误的答案,我需要让游戏回到开头。我需要它询问用户是否希望再次玩游戏,然后循环回到游戏的开头。任何人都知道如何做到这一点,将不胜感激。

这是代码 -

#Python Text Adventure Game
#Created By Callum Fawcett
#Created On 20/07/19
#Version 0.1


# Setup
yes_no = ["yes", "no"]
directions = ["left", "right", "forward", "backward"]

# Introduction
name = input("What is your name, adventurer?\n")
print("Greetings, " + name + ". Let us go on a quest!")
print("You find yourself on the edge of a dark Jungle.")
print("Can you find your way through? and find the Hidden treasure at the end?\n")

# Start of game
response = ""
while response not in yes_no:
    response = input("Would you like to step into the Jungle?\nyes/no\n")
    if response == "yes":
        print("You head into the Jungle. You hear crows cawwing in the distance.\n")
    elif response == "no":
        print("You are not ready for this quest. Goodbye, " + name + ".")
        quit()
    else: 
        print("I didn't understand that.\n")

# Second part of game
response = ""
while response not in directions:
    print("To your left, you see a Tiger.")
    print("To your right, there is more Jungle.")
    print("There is a rock wall directly in front of you.")
    print("Behind you is the Jungle exit.\n")
    response = input("What direction do you move?\nleft/right/forward/backward\n")
    if response == "left":
        print("The Tiger eats you. Farewell, " + name + ".")
        quit()
    elif response == "right":
        print("You head deeper into the Jungle.\n")
    elif response == "forward":
        print("You cannot scale the wall.\n")
        response = "" 
    elif response == "backward":
        print("You leave the Jungle. Goodbye, " + name + ".")
        quit()
    else:
        print("I didn't understand that.\n")

# Third Part of game
response = ""
while response not in directions:
    print("To your left, there is a waterfall.")
    print("To your right, you see a run down house.")
    print("Directly in front of you is a dark staircase.")
    print("Behind you is the exit.\n")
    response = input("What direction do you wish to take?\nleft/right/forward/backward\n")
    if response == "left":
        print("You look off the edge of the waterfall, taking the time to think about your choices.\n")
        response = ""
    elif response == "right":
        print("The house is a trap, the doors and windows all shut behind you and youre trapped, Farewell, " + name + ".")
        quit()
    elif response == "forward":
        print("You head down the strairs\n")
    elif response == "backward":
        print("You leave the Jungle. Goodbye, " + name + ".")
        quit()
    else:
        print("I didn't understand that.\n")

# Fourth part of game
response = ""
while response not in directions:
    print("You're now at the bottom of the staircase, it has a come to a fork")
    print("To the right is a well lit path with a sign that reads 'Death to all who continue'.")
    print("To the left is a dark and gloomy path with a sign that reads 'free passage to all those who continue'. ")
    print("Directly in front of you is a a 50ft drop.")
    print("Behind you is the exit.\n")
    response = input("What direction do you wish to take?\nleft/right/forward/backward\n")
    if response == "left":
        print("You are attacked by forrst deamons. Goodebye," + name + ".")
        quit()
    elif response == "right":
        print("You continue through the forrest.\n")
    elif response == "forward":
        print("You cant go down there youll die.\n")
        response = ""
    elif response == "backward":
        print("You leave the Jungle. Goodebye" + name + ".")
        quit()
    else:
        print("I Didn't understand that.\n")

#Fifth part of game
response = ""
while response not in directions:
    print("You have continued through the dark forrest, and found yourself at a cross road.")
    print("To your left is a beaten path with a man lying on the ground.")
    print("To your right is a door.")
    print("Straight ahead is a dark path that is over grown and full of brambles and thorns.")
    print("behind you is the way you came and the way out.\n")
    response = input("What direction do you wish to take?\nleft/right/forward/backward\n")
    if response == "left":
        print("You walk to help the man, but it was a trap and you are attacked and killed by savages. Goodbye, " + name + ".\n")
        quit()
    elif response == "right":
        print("You go through the door, and it takes you to a mystical realm that you do not know, and now youre traped there. Goodbye, " + name + " Have fun.\n")
        quit()
    elif response == "forward":
        print("You continue through the dark Jungle, getting deeper and deeper. Lets hope you're not lost ;)\n")
    elif response == "backward":
        print("You Leave the Jungle. Goodbye" + name + ".")
        quit()
    else:
        print("I Didn't understand that")

#sixth part of the game.
response = ""
while response not in directions:
    print("You have made it through the thorns and brambles, and have come to a T in the path.")
    print("To your left is a bridge that doesnt look very stable and could break with the slightest bit of weight on it.")
    print("To your right is a dark path with a metal bridge that looks sturdy and safe.")
    print("Directly in front of you is a wall.")
    print("Behind you is the way you came and the way out.\n")
    response = input("What direction do you wish to take?\nleft/right/forward/backward\n")
    if response == "left":
        print("The bridge was actually very safe and you make your way over it, and continue on your quest\n")
    elif response == "right":
        print("The bridge wasnt stable and you have fallen to your death. Goodbye" + name + ".\n")
        quit()
    elif response == "forward":
        print("You cannot scale the wall\n")
        response = ""
    elif response == "backward":
        print("You leave the Jungle. Goodbye" + name + ".")
        quit()
    else:
        print("I Didn't Understand That")

#Final Part of The Game
response = ""
while response not in directions:
    print("You have come to the jungle temple, you make your way in through the door. Once inside you see three doors.")
    print("The door on the left has a weird symbol above it, and what looks like blood coming out from under the door.")
    print("The door on the right has no symbol above it, but does have two large lion statues by the door.")
    print("The door straight in front of you has a crown symbol above it, but has two skelitons sat outside it.")
    print("behind you is the way you came in and the way out.\n")
    response = input("What direction do you wish to take?\nleft/right/forward/backward\n")
    if response == "left":
        print("You open the door and something drags you inside, for you to never be seen again. Goodbye" + name + ".\n")
        quit()
    elif response == "right":
        print("You open the door and go inside, only to find 10 large lions who have not been fed in a very long time, they eat you. Goodbye" + name + ".\n")
        quit()
    elif response == "forward":
        print("You open the door and walk down the strairs infront of you, as you get lower and lower you start to see all the gold and treasure that has been left.")
        print("CONGRATULATIONS " + name + ", you found the Hidden jungle treasure, along with an exit back to the world.")
    elif response == "backward":
        print("You leave the temple and there are re risen soldiers ready to kill you. you die, Goodbye " + name + ".\n")
        quit()
    else:
        print("I Didn't understant that")
亚瑟五世

一个可能的解决方案:将您当前的所有代码移动到一个函数中,我们称其为“游戏玩法”,并将其封装在主函数中的循环中

def gameplay():

    # Setup
    yes_no = ["yes", "no"]
    ....
    ....
    ....

if __name__ == "__main__":
    while True:
        response = input("start a new game?y/n")
        if response != "y":
            break    
        print("Starting a new game")
        gameplay()

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

一旦游戏结束,尝试删除我的重启按钮

来自分类Dev

我可以通过重启按钮来更改井字游戏中的innerHTML,但是一旦重启,我将无法重新分配以开始游戏

来自分类Dev

一旦发生某些事情,我如何退出函数?

来自分类Dev

如何使我的徽标链接回到wordpress二十二子主题中的首页?

来自分类Dev

随机链接,一旦显示出来,我就不希望它再次出现

来自分类Dev

一旦sudo成为root,是否有命令查看我的用户名?

来自分类Dev

一旦我调用 DynamicCapture,我如何从外部检索签名

来自分类Dev

一旦期货开始,您如何杀死期货?

来自分类Dev

为什么一旦通过javascript按钮更改了选择值,我就无法通过html选择选择值?

来自分类Dev

如何使用TFS 2013在“错误工作项”上创建“错误类别”,一旦尝试,我在“参考字段名称”上遇到错误

来自分类Dev

如何在xml的输出中分配到分支的链接,以便一旦我在html的输出中单击它就可以打开它

来自分类Dev

一旦合并了提交,我如何跟踪它们来自何处?

来自分类Dev

一旦使用StreamWriter,我将如何重新启动它?

来自分类Dev

在 Pyplot 中,一旦绘图已经绘制,我们如何更改绘图的线宽?

来自分类Dev

一旦我们使用asort,Php如何按倒序排序?

来自分类Dev

一旦我推送到git repo,如何将我的代码推送到我的VPS?

来自分类Dev

一旦我从我的聊天机器人“交出”,我如何从 Facebook 收件箱实施“交回”

来自分类Dev

一旦包含 postsharp 库,我就无法更改分支

来自分类Dev

Twitter Android-FirebaseUI身份验证:一旦我拥有Android App上的访问令牌和访问密钥,如何代表用户发布?足够了吗?

来自分类Dev

一旦我在STPAddCardViewController()上选择完成,应用程序就会加载并且不会停止加载

来自分类Dev

一旦我在 datepicker 中选择日期然后我再次打开 datepicker 它显示当前日期未选择日期

来自分类Dev

Firebase匿名用户一旦升级

来自分类Dev

我将如何循环回到开始

来自分类Dev

如何在矩形中自动适应文本。一旦我们点击文本,矩形就会出现

来自分类Dev

一旦我在控制台中获得了基础结果,如何将它们放入结构中?

来自分类Dev

一旦活动从另一个功能开始,如何共享数据?

来自分类Dev

一旦开始在Ubuntu 16.04中使用Titan X GPU进行训练,我的Dell XPS机器就会关闭。

来自分类Dev

一旦我的内容超过页脚,我的页面就不会向下滚动

来自分类Dev

一旦我的内容超出页脚,我的页面就不会向下滚动

Related 相关文章

  1. 1

    一旦游戏结束,尝试删除我的重启按钮

  2. 2

    我可以通过重启按钮来更改井字游戏中的innerHTML,但是一旦重启,我将无法重新分配以开始游戏

  3. 3

    一旦发生某些事情,我如何退出函数?

  4. 4

    如何使我的徽标链接回到wordpress二十二子主题中的首页?

  5. 5

    随机链接,一旦显示出来,我就不希望它再次出现

  6. 6

    一旦sudo成为root,是否有命令查看我的用户名?

  7. 7

    一旦我调用 DynamicCapture,我如何从外部检索签名

  8. 8

    一旦期货开始,您如何杀死期货?

  9. 9

    为什么一旦通过javascript按钮更改了选择值,我就无法通过html选择选择值?

  10. 10

    如何使用TFS 2013在“错误工作项”上创建“错误类别”,一旦尝试,我在“参考字段名称”上遇到错误

  11. 11

    如何在xml的输出中分配到分支的链接,以便一旦我在html的输出中单击它就可以打开它

  12. 12

    一旦合并了提交,我如何跟踪它们来自何处?

  13. 13

    一旦使用StreamWriter,我将如何重新启动它?

  14. 14

    在 Pyplot 中,一旦绘图已经绘制,我们如何更改绘图的线宽?

  15. 15

    一旦我们使用asort,Php如何按倒序排序?

  16. 16

    一旦我推送到git repo,如何将我的代码推送到我的VPS?

  17. 17

    一旦我从我的聊天机器人“交出”,我如何从 Facebook 收件箱实施“交回”

  18. 18

    一旦包含 postsharp 库,我就无法更改分支

  19. 19

    Twitter Android-FirebaseUI身份验证:一旦我拥有Android App上的访问令牌和访问密钥,如何代表用户发布?足够了吗?

  20. 20

    一旦我在STPAddCardViewController()上选择完成,应用程序就会加载并且不会停止加载

  21. 21

    一旦我在 datepicker 中选择日期然后我再次打开 datepicker 它显示当前日期未选择日期

  22. 22

    Firebase匿名用户一旦升级

  23. 23

    我将如何循环回到开始

  24. 24

    如何在矩形中自动适应文本。一旦我们点击文本,矩形就会出现

  25. 25

    一旦我在控制台中获得了基础结果,如何将它们放入结构中?

  26. 26

    一旦活动从另一个功能开始,如何共享数据?

  27. 27

    一旦开始在Ubuntu 16.04中使用Titan X GPU进行训练,我的Dell XPS机器就会关闭。

  28. 28

    一旦我的内容超过页脚,我的页面就不会向下滚动

  29. 29

    一旦我的内容超出页脚,我的页面就不会向下滚动

热门标签

归档