首页 > 解决方案 > 用户死亡后如何让游戏循环回到开头

问题描述

#adventure game 当用户进入错误的房间并死亡时,我希望它回到进入哪个房间的问题

prompt = print("You are in a room by yourself. There are three doors; Red, Blue, and Green. Which door are you picking")
user = input("Room?: ")


def red():
    print("You enter the red room and die")
def blue():
    print("You enter the blue room and freeze to death")
def green():
    print("You enter the green room and proceed")

if user == "r":
        red()
        print(prompt)
elif user == "b":
        blue()
        print(prompt)
elif user == "g":
        green()
        print(prompt)

标签: pythonif-statementwhile-looppygameadventure

解决方案


将逻辑包装在一个while True循环中。

只要你不跳出循环,它就会不断重复。


推荐阅读