Hey everyone,
I'm trying work on a text based game and I'm a little stuck with navigating the rooms. So let's say I'm in a room with another room to the north, east, south, and west. I wanted to create a "navigation" function which takes four parameters, which are the rooms that north, east, south, and west respectively. So here's what I got so far:
# direction words bank
direction_words = ["north", "n", "go north", "east", "e", "go east", "west", "w", "go west", "south", "s", "go south"]
north_words = ["north", "n", "go north"]
east_words = ["east", "e", "go east"]
south_words = ["south", "s", "go south"]
west_words = ["west", "w", "go west"]
def navigation(north_room, east_room, south_room, west_room):
# make this function call another function
while True:
decision = raw_input("> ")
if decision in north_words:
print "north"
return north_room
break
elif decision in east_words:
print "east"
return east_room
elif decision in south_words:
print "south"
return south_room
elif decision in west_words:
print "west"
return west_room
else:
print "not_allowed"
def start():
navigation('sphinx_room', 'slingshot_room', 'banana_door', 'foyer')
def sphinx_room():
print "sphinx"
def slingshot_room():
print "slingshot"
def banana_door():
print "banana"
def foyer():
print "foyer."
ROOMS = {
'sphinx_room': sphinx_room()
'slingshot_room': slingshot_room(),
'banana_door': banana_door(),
'foyer': foyer()
}
start()
I created a dict because I figured that's what I probably need to do, but I'm not sure how to implement it.
Basically, I want it so that if you type "north", the function will run the room (which is a function) that is north of you.