def __init__(self): # Load the rooms from the database cursor = Database.room_db.execute("SELECT * FROM rooms") room_list = cursor.fetchall() self.last_backup_time = 0 self.rooms = {} for index, room in enumerate(room_list): try: # Add the new room new_room = Room(room[0], room[1], Database.read_json(room[2])) # Load the items into the room if room[3] is not None: items = Database.read_json(room[3]) for item in items: if Database.item_definitions[item[0]] is not None: new_item = Database.item_definitions[item[0]].clone() new_item.custom_data = item[1] new_room.add_item(new_item) self.rooms[room[0]] = new_room except Exception as err: print("Warning: Exception occurred while processing room at index %s. Please verify the data." % str(index)) if len(room) > 0 and type(room[0]) == str: print("Room name: " + room[0]) print("Exception: " + err.args[0]) # Use the first room in the database as the entry room if len(room_list) > 0: self.entry_room = room_list[0][0] else: self.entry_room = "" print("Uh, server manager sir/ma'am... there aren't any rooms in this dungeon... I'm gonna continue anyway but this isn't cool OK?") # Create player and client list self.players = [] self.clients = [] self.incoming_clients = queue.Queue() # Assign this dungeon to all of the rooms for coordinates, room in self.rooms.items(): room.dungeon = self
"Out the window to your left from where you stand inside of a small kitchen" "You can see a large tower ominously hanging over the valley in the distance", 1) stop = Room( 'Dining Room', 'You walk through the door in front of you to find' 'a beautifully set dining room', 2) hallway = Room('hallway', 'you are in the hallway', 3) hallway2 = Room('upstairs hallway', "You are in the upstairs hallway", 4) bedroom = Room('bedroom', 'you are in the bedroom', 5) bedroom2 = Room('bedroom', 'You are in the bedroom', 6) bedroom3 = Room('bedroom', 'You are in the bedroom', 7) living = Room('living room', 'you are in the living room', 8) inventory = Inventory() current_room = House House.add_item(Stick('Stick', 'This is a quest!')) while True: current_room.enter_room() command = raw_input("What do you want to do?\n") print if command == 'x': break result = current_room.process_command(command, inventory) if isinstance(result, Room): current_room = result result.enter_room() continue elif isinstance(result, str): print result
Beach = Room('Beach', "You find yourself awake on a beach - palm trees swaying in the wind, the ocean breeze upon " "your face, and white sand all around you. \nYou see half of a cruise ship lodged between two rocks" " and a large opening facing you. There is a wallet on the floor about a yard away", 1) stop = Room('Ship Entrance', 'You walk into the large hole in the cruise ship and are in a vast dark space, very' 'lightly lit by the outside world. ', 2) hallway = Room('hallway', 'you are in the hallway', 3) hallway2 = Room('upstairs hallway', "You are in the upstairs hallway", 4) bedroom = Room('bedroom', 'you are in the bedroom', 5) bedroom2 = Room('bedroom', 'You are in the bedroom', 6) bedroom3 = Room('bedroom', 'You are in the bedroom', 7) living = Room('living room', 'you are in the living room', 8) inventory = Inventory() current_room = Beach Beach.add_item(Wallet('Wallet', 'This is a test')) while True: current_room.enter_room() command = raw_input("What do you want to do?\n") print if command == 'x': break result = current_room.process_command(command, inventory) if isinstance(result, Room): current_room = result result.enter_room() continue elif isinstance(result, str): print result