示例#1
0
def process_room_data(data):
    """ Extracts room data from JSON data and converts into a Room object """
    for key, subdict in data.items():
        name = key
        id = subdict["ID"]
        long_desc = subdict["LONGDESC"]
        short_desc = subdict["SHORTDESC"]

        exits = {}
        # Convert list stored in file to {'north' : (RoomID, "Room Name") } format then add to exits dictionary
        if "NORTH" in subdict:
            exits[NORTH] = (subdict["NORTH"][0], subdict["NORTH"][1])
        if "EAST" in subdict:
            exits[EAST] =  (subdict["EAST"][0], subdict["EAST"][1])
        if "SOUTH" in subdict:
            exits[SOUTH] = (subdict["SOUTH"][0], subdict["SOUTH"][1])
        if "WEST" in subdict:
            exits[WEST] = (subdict["WEST"][0], subdict["WEST"][1])

        # Dictionary of Items and NPCs (non-player characters) to be populated when item files are processed
        items = {}
        npcs = {}

        room = classes.Room(id, name, long_desc, short_desc, exits, items, npcs)
        return room
示例#2
0
def maze_maker():
    rooms = []
    room_count = 0
    while room_count < len(MAZE_LIST):
        room = classes.Room('Maze of Boxes {}'.format(room_count))
        rooms.append(room)
        room_count += 1
    room_count = 0
    base_description = 'You are in a maze of storage crates, with boxes piled up to the ceiling.'
    while room_count < len(MAZE_LIST):
        room = rooms[room_count]
        exits = MAZE_LIST[room_count]
        for path in exits.keys():
            exit_index = exits.get(path)
            if exit_index >= 0:
                room.exits[path] = classes.Path(rooms[exit_index])
            elif exit_index == -1:
                room.exits['north'] = classes.Path(CARGO_BAY)
            else:
                room.exits['south'] = classes.Path(CARGO_BAY2)
        if len(exits.keys()) == 1:
            if 'north' in exits.keys():
                path = 'north'
            elif 'south' in exits.keys():
                path = 'south'
            else:
                path = 'east'
            exit_message = '\nYou have reached a dead end. The exit is to the {}.'.format(path)
        else:
            exit_message = '\nThere are exits to the ' + ', '.join(room.get_exit_list()) + '.'
        room.set_description(base_description + exit_message)
        room_count += 1
    return rooms
示例#3
0
def add_room():
    new_id = functions.get_room_id_increment()
    room = classes.Room(id=new_id,
                        nome=request.form['nome'],
                        dimensione=request.form['dim'])
    session.add(room)
    session.commit()
    return redirect(url_for('confirm'))
示例#4
0
def initialize_rooms():
    # jewels, weapons, weapon_name, room_name, room_desc, room_id, north, south, east, west

    # rooms = []

    desc = "You find yourself deep in catacombs. The light from the entrance is dim and \nfar away, but bright enough for you to follow."
    first = classes.Room(0, 0, None, "a deep cave", desc, 1, None, None, None,
                         None)
    # rooms.append(first)

    desc = "As the light grows brighter, your eyes are caught by the gleam of metal and \
	\njewels in the corner. A small pile of rubies sits on a rough rock ledge, while a \
	\ndagger rests on the floor beneath."

    second = classes.Room(3, 1, "a dagger", "a dimly lit cave", desc, 2, None,
                          None, None, first)
    first.east = second

    desc = "You squeeze into the next catacomb, which is considerably narrower than the \nfirst. The exit is blocked by a squat troll, whose ax dissuades you from \
		\npassing. 'You can pass if you solve a puzzle,' the troll growls at you. \nYou have no choice but to agree."

    third = classes.Room(4, 1, "a helmet", "a narrow catacomb", desc, 3, first,
                         None, None, None)
    second.south = third

    desc = "Your relief at making it past the gnome turns to delight as you find yourself in a new cavern.\
		    \nThis one is draped in velvet, fur, strings of jewelry, and piles of gold. Who would leave \
		    \nsuch riches laying about?"

    fourth = classes.Room(5, 0, None, "an opulant room", desc, 4, None, None,
                          third, None)
    third.west = fourth

    desc = "This room in the cave is not nearly so pleasant. It smells musty and is covered\nin thick cobwebs. You do your best to pick through them. As you step to the \
			\nsideto avoid an intact web, your foot kicks up against a locked chest. You \ndon't see a key, but as you touch the lock, a voice hums in your mind:\
			\n'Solve a riddle to gain a reward.'"

    fifth = classes.Room(4, 1, "a mace", "a cobwebbed cave", desc, 5, fourth,
                         None, None, None)
    fourth.south = fifth

    desc = "You enter what appears to be an armory. Racks and racks of swords, shields, and\nspears fill the large space. You consider grabbing one before moving on."
    sixth = classes.Room(0, 1, "a shield", "an armory", desc, 6, None, None,
                         None, fifth)
    fifth.east = sixth

    desc = "There are cockroaches everywhere. Your stomach churns, and you try to ignore \
			\nthe crunching as you stride quickly across the room.The gleam of metal and \
			\njewels again catches your eye - but it is tempting to move on without \
			\ninvestigating."

    seventh = classes.Room(3, 1, "a throwing star",
                           "a cave covered in cockroaches", desc, 7, None,
                           None, None, sixth)
    sixth.east = seventh

    desc = "The good news is that you've made it through the room full of cockroaches. The \nbad news is that the ceiling of this small cave is covered in bats.\
			\n'Why don't they eat the cockroaches?' you wonder. A few of them stir when \nyou walk in, but for the most part, they seem to be asleep.\
			\nYou are tempted by a satchel of jewels hanging from the hilt of a broadsword \nthat is leaned against the wall."

    eighth = classes.Room(3, 1, "a broadsword", "a cave filled with bats",
                          desc, 8, None, seventh, None, None)
    seventh.north = eighth

    desc = "The light from the entrance, which has been growing progressively brighter, \
			\nbeams clearly into the room as you walk in. You freeze when you \
			\nsee a serpent blocking your path. The serpent raises its head and hisses \nat you, 'You musssst anssssswer a quessssstion iffff you want to esssscape.'"

    ninth = classes.Room(4, 1, "a spear", "a bright room", desc, 9, None, None,
                         None, eighth)
    eighth.east = ninth

    desc = "You find yourself at the mouth of the cave. Just one problem: you find a dragon\nat the mouth of the cave, too. It rumbles at you, smoke curling up from its \
			\nnostrils. You consider trying to dash past it, but there is not enough room \nfor you to squeeze past without being caught. You consider bribing or slaying \
			\nthe dragon."

    tenth = classes.Room(0, 0, None, "the cave opening", desc, 10, None, ninth,
                         None, None)
    ninth.north = tenth

    desc = "You did it! You've never been so relieved to see the sky."
    last = classes.Room(0, 0, None, "the open air", desc, 11, None, None, None,
                        None)
    tenth.north = last

    game_map = classes.Map(first, last)

    return game_map
示例#5
0
"""
This is a game called 'The Room.' It is a text-based game.
"""

import classes as cl

game = cl.Room()

game.wake_up()
示例#6
0
'''
PROMPT = '=> '

HELP = """To move around the map, type the direction you'd like to travel in.
You can go in one of the cardinal directions: NORTH, SOUTH, EAST, and WEST, 
or in some rooms you can go UP or DOWN. 
To get a description of the room you are currently in, type LOOK (l).
For a list of exits out of your current location, type EXITS.

To interact with objects, try EXAMINE (x), TAKE, DROP, or USE. You
can also UNLOCK certain doors with the right key. To check what is in
your inventory, use INVENTORY (i).
If you are done playing, use QUIT (q)."""

##define rooms:
BLANK = classes.Room('Unfinished Room')
CREW_QUARTERS = classes.Room('Crew Quarters')
CAPT_QUARTERS = classes.Room("Captain's Quarters")
HALLWAY= classes.Room('Hallway')
BRIDGE = classes.Room('Bridge')
CARGO_BAY = classes.Room('Cargo Bay, North End')
CARGO_BAY2 = classes.Room('Cargo Bay, South End')
MESS_REC = classes.Room('Mess Hall and Rec Area')
LAB = classes.Room('Laboratory, South End')
SICK_BAY = classes.Room('Sick Bay')
ENGINE_ROOM = classes.Room('Engine Room')
SHUTTLE_BAY = classes.Room('Shuttle Bay')
SHUTTLE_INTERIOR = classes.Room('Shuttle Interior')
LAB2 = classes.Room('Laboratory, North End')
MAZE = []
##define objects: