在没有systemexit.exit()
的文字游戏中,有没有办法让我的代码在“死亡”之后重复?
我尝试搜索循环,但一无所获,我在网上查看了其他游戏,并且在该网站上搜索了可以帮助您的内容
if option==1:
print('\nyou break the front bericade but as you walk in you see a laser streatching across the door frame a little too late, you died')
thisdict["death"] = True
print('\nyou died')
SystemExit.exit()
我只想说你死了,然后一开始就这样说,但是系统退出并不能很好地完成工作。
答案 0 :(得分:0)
使用循环,准备游戏状态字典并调用游戏功能。 死亡时,退出游戏,要求继续并创建一个“新”游戏状态字典:
def game(starter):
# do stuff
lr = input(f"Hello {starter['name']} - nothing to see but go Left or Right? [L,R]: ").lower()
if lr == "left":
return # doing anything is futile, you die anyhow
else:
return # doing anything is futile, you die anyhow
def main():
state = {"name": "someone"}
while True:
game(state)
if not input("You are dead - Play again? [y,n]").lower() == "y":
break
# create new games state dict (just altering the name here)
state["name"] += "_again"
print("bye")
main()
输出:
Hello someone - nothing to see but go Left or Right? [L,R]: l
You are dead - Play again? [y,n] y
Hello someone_again - nothing to see but go Left or Right? [L,R]: r
You are dead - Play again? [y,n] y
Hello someone_again_again - nothing to see but go Left or Right? [L,R]: nothing
You are dead - Play again? [y,n] n
bye