这是我为 CS 课程制作的文本冒险游戏的一小部分。您正在探索一所房子,并通过告诉游戏您要向北、向南、向东或向西移动来导航它。
所以我想添加一些东西来告诉你当你输入了一个无效的输入时,如果你说拼错了像 Nroth、Suoth、Eas 或 West 这样的词之一。这些只是示例,但希望您知道我的意思,如果它不完全匹配北、南、东或西。我将如何在这部分代码中做到这一点?
我举了一个我想输出的错误的例子,如果你拼写错误,上面写着“elif room ==”porch”,但它应该继续询问你想去哪个方向,即使你得到那个错误,因为截至现在它会继续询问您想去哪个方向,无论您输入什么,它都不会输出根据您进入的房间应该说的文本。
def pickRoom(direction, room):
if(direction == "quit") or (direction == "exit"):
print("Better luck next time!")
return "Exit"
elif room == "Porch":
if direction == "North":
return "Pantry"
else:
print("That is not a valid entry!")
elif room == "Pantry":
if direction == "North":
return "Kitchen"
elif direction == "East":
return "DiningRoom"
elif room == "DiningRoom":
if direction == "West":
return "Pantry"
elif room == "Kitchen":
if direction == "West":
return "LivingRoom"
elif direction == "East":
return "Bedroom"
elif room == "Bedroom":
if direction == "West":
return "Kitchen"
elif room == "LivingRoom":
if direction == "West":
return "Bathroom"
elif direction == "North":
return "Stairs"
elif room == "Bathroom":
if direction == "East":
return "LivingRoom"
elif room == "Stairs":
if direction == "South":
return "Bar"
elif room == "Bar":
if direction == "East":
return "Shop"
elif room == "Shop":
if direction == "North":
return "Closet"
elif direction == "South":
return "Storage"
elif room == "Storage":
if direction == "North":
return "Shop"
elif room == "Closet":
if direction == "South":
return "Shop"
如果您需要更大的代码部分甚至整个 .py 文件来弄清楚,请告诉我,谢谢。
哔哔one
桃花长相依
相关分类