Пример #1
0
def test_bag_take_random(randrange):
    """We can select and remove an item from a bag at random."""
    bag = Bag(['a', 'b', 'c'])
    items = list(bag)
    assert bag.take_random() == items[0]
    assert bag == Bag(items[1:])
    randrange.assert_called_once_with(3)
Пример #2
0
    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)

        self.objects = Bag()
        for obj in objects:
            self.objects.add(obj)

        self.north = north
        self.northeast = northeast
        self.east = east
        self.southeast = southeast
        self.south = south
        self.southwest = southwest
        self.west = west
        self.northwest = northwest

        self.enter_scene = None
        self.exit_scene = None
Пример #3
0
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)

        self.objects = Bag()
        for obj in objects:
            self.objects.add(obj)

        self.north = north
        self.northeast = northeast
        self.east = east
        self.southeast = southeast
        self.south = south
        self.southwest = southwest
        self.west = west
        self.northwest = northwest

        self.enter_scene = None
        self.exit_scene = None

    def __str__(self):
        return F"--- {self.name} ---\n{self.description}"
Пример #4
0
 def __init__(self,
              name,
              desc,
              aliases=[],
              isa=[],
              state=None,
              color=Fore.LIGHTBLACK_EX):
     super().__init__(name, *aliases)
     self.isa = isa
     self.desc = desc
     self.state = state
     self.color = color
     self.scene = None
     self.items = Bag()
Пример #5
0
 def __init__(self,
              name,
              desc,
              aliases=[],
              isa=[],
              state=None,
              color=Fore.LIGHTBLACK_EX,
              undroppable=False,
              real_obj=None,
              action=None):
     super().__init__(name, *aliases)
     self.isa = isa
     self.desc = desc
     self.state = state
     self.color = color
     self.scene = None
     self.real_obj = real_obj
     self.__action = action
     self.undroppable = undroppable
     # Items on or in the Objec that can be removed
     self.items = Bag()
     # Parts of the Object. They can be interacted with, but not removed.
     self.parts = Bag()
Пример #6
0
def test_bag_find():
    name, *aliases = ['Name', 'UPPER ALIAS', 'lower alias']
    bag = Bag({Item(name, *aliases)})

    assert bag.find('name')
    assert bag.find('Name')
    assert bag.find('NAME')
    assert bag.find('upper alias')
    assert bag.find('LOWER ALIAS')
    assert not bag.find('other')
Пример #7
0
def test_bag_find():
    """We can find items in a bag by name, case insensitively."""
    name, *aliases = ['Name', 'UPPER ALIAS', 'lower alias']
    bag = Bag({Item(name, *aliases)})

    assert bag.find('name')
    assert bag.find('Name')
    assert bag.find('NAME')
    assert bag.find('upper alias')
    assert bag.find('LOWER ALIAS')
    assert not bag.find('other')
def test_bag_find():
    """We can find items in a bag by name, case insensitively."""
    name, *aliases = ['Name', 'UPPER ALIAS', 'lower alias']
    named_item = Item(name, *aliases)
    appellative_item = Item('appellation', *aliases)
    nameless_item = Item('noname', 'none at all')
    bag = Bag({named_item, appellative_item, nameless_item})

    assert bag.find('name') is named_item
    assert bag.find('Name') is named_item
    assert bag.find('NAME') is named_item
    assert bag.find('appellation') is appellative_item
    assert bag.find('upper alias') in {named_item, appellative_item}
    assert bag.find('LOWER ALIAS') in {named_item, appellative_item}
    assert not bag.find('other')
Пример #9
0
def test_empty_bag_get_random():
    """Choosing from an empty bag returns None."""
    bag = Bag()
    assert bag.get_random() is None
Пример #10
0
def test_bag_get_random2(randrange):
    """We can select an item from a bag at random."""
    bag = Bag(['a', 'b', 'c'])
    assert bag.get_random() == list(bag)[1]
    randrange.assert_called_once_with(3)
def test_bag_get_random(randrange):
    """We can select an item from a bag at random."""
    bag = Bag(map(Item, 'abc'))
    assert bag.get_random() == list(bag)[0]
    randrange.assert_called_once_with(3)
Пример #12
0
class Notebook(Item):
    letters_found = Bag()
Пример #13
0
from __future__ import (nested_scopes, generators, division, absolute_import,
                        with_statement, print_function, unicode_literals)
# import pickle

# 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.
""")