コード例 #1
0
def test_say_room():
    """saw() will format input as strings."""
    r = Room('You are standing in a hallway.')

    buf = StringIO()
    with redirect_stdout(buf):
        say(r)
    assert buf.getvalue() == 'You are standing in a hallway.\n'
コード例 #2
0
from adventurelib import Bag, Room

Room.add_direction('northeast', 'southwest')
Room.add_direction('northwest', 'southeast')


class Space(Room):
    # items   - Items in the room that can be picked up.
    # objects - Items in the room that are stationary but can be interacted with:
    #           I.e. doors, windows, floor, carpet, large paintings, etc.
    # NESW    - Exit to another room in that direction.
    def __init__(self,
                 name,
                 desc,
                 items=[],
                 objects=[],
                 north=None,
                 northeast=None,
                 east=None,
                 southeast=None,
                 south=None,
                 southwest=None,
                 west=None,
                 northwest=None):
        super().__init__(desc)
        self.name = name

        self.items = Bag()
        for item in items:
            self.items.add(item)
コード例 #3
0
ファイル: story.py プロジェクト: bdavs/adventurelib
# from adventurelib import *
from adventurelib import Room, Item, say, when, Bag, start, set_context
# , get_context
import mechanics

# initialize rooms
Room.items = Bag()
Room.gold = 0
Room.visited = 0

# locations
Width = 7
Height = 7
Room_List = []
for x in range(0, Width):
    Room_List.append([Room("") for y in range(0, Height)])

current_room = starting_room = Room_List[3][0] = Room("""
You awaken in a dungeon cellar. In your hands lies a notebook which reads,
Take me with you to find the letters. Only one phrase will set you free.
""")
starting_room.visited = 1

Room_List[3][1] = Room_List[3][0].north = Room("""
You enter a dimly lit room which smells of elderberries.
""")

Room_List[3][2] = Room_List[3][1].north = Room("""
You enter a brighter room with a desk at its center and one chair.
""")