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
        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
            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." 
    'sphinx_room': sphinx_room()
    'slingshot_room': slingshot_room(),
    'banana_door': banana_door(),
    'foyer': foyer()


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.

If you have 5 rooms shaped as a plus sign, with room #5 in the middle, you would create the relationships with a dictionary as follows.

def room_function(room_no):
    print "running function for %s" % (room_no)

    room #1=North clockwise so room #4=West and room #5=the middle
    rooms_dict is keyed on the room number and points to the direction
    that the player can move from this room and those room number(s)

rooms_dict={1:("S", "5"),
            2:("W", "5"),
            3:("N", "5"),
            4:("E", "5"),
            5:("NESW", "1234")}

direction, new_room_no = rooms_dict[room_no]
if to_go in direction:
    print "go %s to room number %s" % (to_go, next_room)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.