python - 用户死亡后如何让游戏循环回到开头
问题描述
#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)
解决方案
将逻辑包装在一个while True
循环中。
只要你不跳出循环,它就会不断重复。
推荐阅读
- javascript - 如何使用javascript在嵌套对象数组中按属性分配值
- asp.net - 在 MVC5 的列表中显示 Ping 状态
- angular - Angular - 在父容器内打开底部表 (MatBottomSheet)
- c# - NuGet 中传递包引用的最佳实践
- javascript - Lambda函数返回具有不同内存位置的函数?
- php - 从 PHP 中的嵌套数组中删除元素
- django - 如何覆盖默认的 Django 表单验证错误
- java - 从 Internet 获取 xml 文件时为 == null
- windows - ~t 返回空白而不是时间
- php - 如何在使用 symfony 保存缓存时修复“touch(): Utime failed: Operation not allowed”?