我正在为我的第一个大型自制Python项目制作一款文本冒险游戏。我试图找出如何让玩家能够回到之前的区域,从而做出另一个选择。我不知道该怎么做。知道怎么做吗?
answer_yes = ["Yes" ,"Y" ,"yes" ,"y" ]
answer_no = ["No" ,"N", "no", "n"]
answer_north = ["North", "N"]
answer_south = ["South", "S"]
answer_east = ["East", "E"]
answer_west = ["West" "W"]
print("""
Welcome to Ziggy's Adventure
You are standing in a field, north of the coast, to your north is a beach, to your west is a dirt path, which way will you go?
""")
ans1 = input(">>")
if ans1 in answer_north:
print(
"n You arrive at the beach, the sound of seagulls and the salty sea air, you can see the beach, "
"there is nothing much here. Where will you go now?")
ans1
此处使用while循环。
answer_yes = ["Yes" ,"Y" ,"yes" ,"y" ]
answer_no = ["No" ,"N", "no", "n"]
answer_north = ["North", "N"]
answer_south = ["South", "S"]
answer_east = ["East", "E"]
answer_west = ["West" "W"]
while True:
print("""
Welcome to Ziggy's Adventure
You are standing in a field, north of the coast, to your north is a beach, to your west is a dirt path, which way will you go?
""")
ans1 = input(">>")
if ans1.lower() == 'exit': # add an if statement if input is exit then exit(break) the loop.
break
if ans1 in answer_north:
print(
"n You arrive at the beach, the sound of seagulls and the salty sea air, you can see the beach, "
"there is nothing much here. Where will you go now?")