You really need to link exits. In all text adventure games, moving in a direction is done via a single letter: n, e, s, w, u, d (up and down are the last 2). You really should assign exits to rooms, and be able to easily link rooms to exits, as I showed in my example above.
Also, I would not include the name of the room in the class defintion, I'd use the name as the key in a dictionary. The dictionary is a mapping of room names to Room objects
Also, you need to use the class constructor. Why pass in the name if you don't assign it in the constructor? In my rooms, all Room variables require at least 2 things: description and exits (as a list of dictionaries). Create your constructor to take those in and use them:
class Room:
def __init__(self, description, exits):
self.desc = description
self.exits = exits
self.items = []
self.actions = []
# This creates a room with the key being the room name Entrance, and the single exit n (north) leads to the room Town_Gate
Rooms['Entrance'] = Room("You are at the entrance to a town", {'n' : 'Town_Gate'})
# This creates a room with the key being the room name Town_Gate, and 2 exits, s, back to entrance and e leads to the room Town_Square
Rooms['Town_Gate'] = Room("You are at the gates of the town.", {'s' : 'Entrance', 'e' : 'Town_Square'})
# This is copied almost EXACTLY from my post a few posts ago, it just shows how you use the variable CurrentRoom, which is the key into the dictionary Rooms
# start at entrance
currentRoom = 'entrance'
while isRunning:
# print the description of the current room
print Rooms[currentRoom].description
# list the items in the room
if Rooms[currentRoom].items:
while item in Rooms[currentRoom].items:
print ' You see a ' + item
print 'The available exits are: '
while exitDirs in Rooms[currentRoom].exits:
print exitDirs
print 'command> '
# get the command
# check for all the generic commands: look, invenrtory, help, quit, etc.
# loop through all the possible exits for this room
while exitDirs in Rooms[currentRoom].exits:
if command[0] == exitDirs:
# change our room to this one
currentRoom = Rooms[currentRoom].exits[exitDirs]
break
# if the user issues a get for the 1st word, check the item is in the room...
if command[0] == 'get':
while item in Rooms[currentRoom].Items:
# if so, add the item to the inventory, and remove the item form the room
if command[1] == item:
Inventory.append(item)
Rooms.currentRoom].Items.remove(item)
# check if the user performed some available action
while action in Rooms[currentRoom].actions:
if command == action:
PerformAction(currentRoom, action)
break
def PerformAction(currentRoom, action):
# check the room versus the action and see if it's still viable