This is a small section from a text adventure game I am making for a CS class. You are exploring a house and you navigate it by telling the game if you want to go north, south, east or west.
So I wanted to add something to tell you when you have entered an invalid input, if you say misspelled one of the words like Nroth, Suoth, Eas, or Weast. These are just examples but hopefully you know what I mean, just if it doesn't match exactly north, south, east or west.
How would I do that within this section of code?
I made an example of the error I want to to output if you made a spelling mistake where it says "elif room == "porch" but it should continue asking which direction you want to go, even if you get that error because as of now it continues asking which direction you want to go and no matter what you put in, it does not output the text that is supposed to be said depending on which room you enter.
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"
Let me know if you need a larger section of the code or even the whole .py file to figure it out, thanks.