コード例 #1
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
 def test_aliases(self):
     loc = Location("hall", "empty hall")
     exit = Exit("up", "attic", "ladder to attic")
     door = Door("door", "street", "door to street")
     exit2 = Exit(["down", "hatch", "manhole"], "underground",
                  "hatch to underground")
     door2 = Door(["east", "garden"], "garden", "door east to garden")
     self.assertEqual("up", exit.name)
     self.assertEqual("door", door.name)
     loc.add_exits([exit, door, exit2, door2])
     self.assertEqual(
         {"up", "door", "down", "hatch", "manhole", "east", "garden"},
         set(loc.exits.keys()))
     self.assertEqual(loc.exits["down"], loc.exits["hatch"])
コード例 #2
0
    def test_door_pair(self):
        loc1 = Location("room1", "room one")
        loc2 = Location("room2", "room two")
        key = Key("key")
        door_one_two = Door("two", loc2, "door to room two", locked=True, opened=False)
        door_two_one = door_one_two.reverse_door("one", loc1, "door to room one", reverse_open_msg="door one open", reverse_close_msg="door one close",
                                                 this_open_msg="door two open", this_close_msg="door two close")
        loc1.add_exits([door_one_two])
        loc2.add_exits([door_two_one])
        door_one_two.key_code = 555
        key.key_for(door_one_two)
        pubsub1 = PubsubCollector()
        pubsub2 = PubsubCollector()
        loc1.get_wiretap().subscribe(pubsub1)
        loc2.get_wiretap().subscribe(pubsub2)
        self.assertTrue(door_two_one.locked)
        self.assertFalse(door_two_one.opened)
        lucy = Living("lucy", "f")

        door_two_one.unlock(lucy, item=key)
        self.assertFalse(door_one_two.locked)
        door_two_one.open(lucy)
        self.assertTrue(door_one_two.opened)
        pubsub.sync()
        self.assertEqual(["door one open"], pubsub1.messages)
        self.assertEqual([], pubsub2.messages)
        door_one_two.close(lucy)
        door_one_two.lock(lucy, item=key)
        self.assertTrue(door_two_one.locked)
        self.assertFalse(door_two_one.opened)
        pubsub1.clear()
        pubsub2.clear()
        pubsub.sync()
        self.assertEqual([], pubsub1.messages)
        self.assertEqual(["door two close"], pubsub2.messages)
コード例 #3
0
ファイル: circle_locations.py プロジェクト: vtbassmatt/Tale
def make_exit(c_exit: SimpleNamespace) -> Exit:
    """Create an instance of a door or exit for the given circle exit"""
    if c_exit.type in ("normal", "pickproof"):  # @todo other door types? reverse doors? locks/keys?
        door = Door(c_exit.direction, make_location(c_exit.roomlink), c_exit.desc)
        door.aliases |= c_exit.keywords
        return door
    else:
        exit = Exit(c_exit.direction, make_location(c_exit.roomlink), c_exit.desc)
        exit.aliases |= c_exit.keywords
        return exit
コード例 #4
0
ファイル: __init__.py プロジェクト: skirtap/Tale
def make_exit(c_exit):
    """Create an instance of a door or exit for the given circle exit"""
    if c_exit.type in ("normal", "pickproof"):
        xt = Door(c_exit.direction, make_location(c_exit.roomlink),
                  c_exit.desc)
    else:
        xt = Exit(c_exit.direction, make_location(c_exit.roomlink),
                  c_exit.desc)
    xt.aliases |= c_exit.keywords
    return xt
コード例 #5
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
    def test_door_pair(self):
        loc1 = Location("room1", "room one")
        loc2 = Location("room2", "room two")
        key = Key("key")
        door_one_two = Door("two",
                            loc2,
                            "door to room two",
                            locked=True,
                            opened=False)
        door_two_one = door_one_two.reverse_door(
            "one",
            loc1,
            "door to room one",
            reverse_open_msg="door one open",
            reverse_close_msg="door one close",
            this_open_msg="door two open",
            this_close_msg="door two close")
        loc1.add_exits([door_one_two])
        loc2.add_exits([door_two_one])
        door_one_two.key_code = 555
        key.key_for(door_one_two)
        pubsub1 = PubsubCollector()
        pubsub2 = PubsubCollector()
        loc1.get_wiretap().subscribe(pubsub1)
        loc2.get_wiretap().subscribe(pubsub2)
        self.assertTrue(door_two_one.locked)
        self.assertFalse(door_two_one.opened)
        lucy = Living("lucy", "f")

        door_two_one.unlock(lucy, item=key)
        self.assertFalse(door_one_two.locked)
        door_two_one.open(lucy)
        self.assertTrue(door_one_two.opened)
        pubsub.sync()
        self.assertEqual(["door one open"], pubsub1.messages)
        self.assertEqual([], pubsub2.messages)
        door_one_two.close(lucy)
        door_one_two.lock(lucy, item=key)
        self.assertTrue(door_two_one.locked)
        self.assertFalse(door_two_one.opened)
        pubsub1.clear()
        pubsub2.clear()
        pubsub.sync()
        self.assertEqual([], pubsub1.messages)
        self.assertEqual(["door two close"], pubsub2.messages)
コード例 #6
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
    def test_title_name(self):
        door = Door("north",
                    "hall",
                    "a locked door",
                    locked=True,
                    opened=False)
        self.assertEqual("north", door.name)
        self.assertEqual("Exit to <unbound:hall>", door.title)
        exit = Exit("outside", "town.square", "someplace")
        self.assertEqual("outside", exit.name)
        self.assertEqual("Exit to <unbound:town.square>", exit.title)

        class ModuleDummy(object):
            pass

        zones = ModuleDummy()
        zones.town = ModuleDummy()
        zones.town.square = Location("square")
        exit._bind_target(zones)
        self.assertEqual("Exit to square", exit.title)
        self.assertEqual("exit to square", exit.name)
コード例 #7
0
ファイル: house.py プロジェクト: skirtap/Tale
        # player has entered!
        player.story_completed()


livingroom = Location(
    "Living room",
    "The living room in your home in the outskirts of the city.")
closet = Location("Closet", "A small room.")
outside = GameEnd("Outside", "It is beautiful weather outside.")

# define the exits that connect the locations

door = Door(
    ["garden", "door"],
    outside,
    "A door leads to the garden.",
    "There's a heavy door here that leads to the garden outside the house.",
    locked=True,
    opened=False)
door.key_code = 1
# use an exit with an unbound target (string), the driver will link this up:
closet_exit = Exit("closet", "house.closet",
                   "There's a small closet in your house.")
livingroom.add_exits([door, closet_exit])
# use another exit with a bound target (object):
closet.add_exits(
    [Exit("living room", livingroom, "You can see the living room.")])

# define items and NPCs

コード例 #8
0
ファイル: houses.py プロジェクト: MitsuharuEishi/Tale
def init(driver):
    # called when zone is first loaded
    pass


# ----------------- START House & Kitchen  -------------------------

livingroom = Location("Living room", "The living room in your little home. Your big TV hangs on a wall.")
livingroom.add_extradesc({"plasma", "tv"}, "You recently bought a bigger TV, but haven't yet found the time to actually watch anything.")
kitchen = Location("Kitchen", "A small but well supplied kitchen. Rather than ordering take-away, "
                              "you prefer cooking your own meals -- unlike most of the other people you know in town. A window lets you look outside.")
kitchen.add_extradesc({"window", "outside"}, "Through the kitchen window you can see your small garden and behind that, the children's playground.")

#  Exits

front_door = Door(["door", "outside", "street"], "magnolia_st.street1", "Your front door leads outside, to the street.",
                  "There's a heavy front door here that leads to the streets outside.", opened=False)
house_door = front_door.reverse_door(["house", "north", "inside"], livingroom,
                                     "You can go back inside your house.", "It's your house, on the north side of the street.",
                                     reverse_open_msg="Someone outside opens the door.",
                                     reverse_close_msg="Someone outside closes the door.",
                                     this_open_msg="Someone in the house opens the door.",
                                     this_close_msg="Someone in the house closes the door.")
livingroom.add_exits([
    Exit("kitchen", kitchen, "Your kitchen is adjacent to this room.",
                             "You can see your kitchen. The previous house owners had a door there but you removed it."),
    front_door
])

kitchen.add_exits([
    Exit(["living room", "livingroom", "back"], livingroom, "The living room is back the way you entered.")
])
コード例 #9
0
        )
        raise StoryCompleted


# Create location

##### Living Room #####
livingroom_descr = """
    The living room in your home in the outskirts of the city."""
livingroom = Location(name="Living room", descr=livingroom_descr)
# Build Exits
garden_door = Door(
    directions=["garden", "door"],
    target_location="house.outside",
    short_descr="A door leads to the garden.",
    long_descr=
    "There's a heavy door here that leads to the garden outside the house.",
    locked=True,
    opened=False,
    key_code="1")

lr_closet = Exit(directions="closet",
                 target_location="house.closet",
                 short_descr="There is a small closet in your house.",
                 long_descr=None)

livingroom.add_exits([garden_door, lr_closet])

# Insert items & npcs
livingroom.insert(cat, None)
livingroom.insert(elastic_band.clone(), None)
コード例 #10
0

class AlleyOfDoors(Location):
    def notify_player_arrived(self, player: Player,
                              previous_location: Location) -> None:
        if previous_location is self:
            player.tell(
                "...Weird... The door you just entered seems to go back to the same place you came from..."
            )


alley = AlleyOfDoors("Alley of doors", "An alley filled with doors.")
descr = "The doors seem to be connected to the computer nearby."
door1 = Door(["first door", "door one"],
             alley,
             "There's a door marked `door one'.",
             long_descr=descr,
             locked=False,
             opened=True)
door2 = Door(["second door", "door two"],
             alley,
             "There's a door marked `door two'.",
             long_descr=descr,
             locked=True,
             opened=False)
door3 = Door(["third door", "door three"],
             alley,
             "There's a door marked `door three'.",
             long_descr=descr,
             locked=False,
             opened=False)
door4 = Door(["fourth door", "door four"],
コード例 #11
0
 def test_with_key(self):
     player = Player("julie", "f")
     key = Key("key", "door key")
     key.key_for(code=12345)
     hall = Location("hall")
     door = Door("north", hall, "a locked door", locked=True, opened=False)
     door2 = Door("south", hall, "another locked door", locked=True, opened=False)
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     with self.assertRaises(ActionRefused):
         door.unlock(player, key)
     door.key_code = 12345
     door2.key_code = 9999
     key.key_for(door)
     self.assertTrue(door.locked)
     door.unlock(player, key)
     self.assertFalse(door.locked)
     with self.assertRaises(ActionRefused):
         door2.unlock(key)
     door.locked = True
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     key.move(player, player)
     door.unlock(player)
     self.assertFalse(door.locked)
     door.lock(player)
     self.assertTrue(door.locked)
     door.unlock(player)
     player.remove(key, player)
     with self.assertRaises(ActionRefused):
         door.lock(player)
     door.key_code = None
     with self.assertRaises(LocationIntegrityError):
         key.key_for(door)
コード例 #12
0
ファイル: rose_st.py プロジェクト: irmen/Tale

carpark = CarPark("Car Parking", "There are a few cars still parked over here. Their owners are nowhere to be seen. "
                                 "One yellow convertible grabs your attention.")
carpark.add_extradesc({"cars"}, "They look abandoned. The doors are all locked, except the doors of the yellow convertible.")
carpark.add_extradesc({"convertible", "yellow"}, "It is a small two-seater and the doors are open. You can't believe your eyes, "
                                                 "but the key is actually still in the ignition!")

# not enough to buy the medicine, player needs to find more, or haggle:
carpark.init_inventory([Money("wallet", 16.0, title="someone's wallet",
                              short_descr="Someone's wallet lies on the pavement, "
                                          "they seem to have lost it. There's some money in it.")])


parking_gate, _ = Door.connect(north_street, ["gate", "parking"],
                               "Through the iron gate you can see the car parking. A few cars are still parked there, it seems.",
                               None, carpark, ["gate", "street"], "Rose street is back through the gate.", None,
                               locked=True, opened=False, key_code="carpark-gate")

parking_key = Key("key", "rusty key", descr="It is what appears to be an old key, with a label on it.",
                  short_descr="On the ground is a key, it's become quite rusty.")
parking_key.key_for(parking_gate)
parking_key.add_extradesc({"label"}, "The label says: `parking area gate'.")


class StorageRoom(Location):
    @call_periodically(5.0, 20.0)
    def shiver_from_cold(self, ctx: Context) -> None:
        # it's cold in the storage room, it makes people shiver
        if self.livings:
            living = random.choice(list(self.livings))
            living.do_socialize("shiver")
コード例 #13
0
ファイル: house_tpl.py プロジェクト: Ianax/Tale
        raise StoryCompleted


livingroom = Location(
    "Living room",
    "The living room in your home in the outskirts of the city.")
closet = Location("Closet", "A small room.")
outside = GameEnd("Outside", "It is beautiful weather outside.")

# define the exits that connect the locations

door = Door(
    ["garden", "door"],
    outside,
    "A door leads to the garden.",
    "There's a heavy door here that leads to the garden outside the house.",
    locked=True,
    opened=False,
    key_code="1"
)  # oneway door, once outside you're finished, so no reason to go back in
livingroom.add_exits([door])

Exit.connect(livingroom, "closet", "There's a small closet in your house.",
             None, closet, ["living room", "back"],
             "You can see the living room where you came from.", None)

# define items and NPCs


class Cat(Living):
    def init(self) -> None:
コード例 #14
0
ファイル: magnolia_st.py プロジェクト: irmen/Tale
import random
from tale.base import Location, Exit, Door, Item
from tale.util import call_periodically, Context
from zones import houses, rose_st
from zones.npcs import Apothecary, Wanderer


street1 = Location("Magnolia Street", "Your house is on Magnolia Street, one of the larger streets in town. "
                                      "The rest of the town lies eastwards.")
street2 = Location("Magnolia Street", "Another part of the street.")
street3 = Location("Magnolia Street (east)", "The eastern part of Magnolia Street.")


Door.connect(houses.livingroom,
             ["door", "outside", "street"], "Your front door leads outside, to the street.",
             "There's a heavy front door here that leads to the streets outside.",
             street1,
             ["house", "north", "inside"], "You can go back inside your house.",
             "It's your house, on the north side of the street.")


pharmacy = Location("Pharmacy", "A pharmacy. It is completely empty, all medicine seems gone.")

Exit.connect(pharmacy, ["east", "outside", "street"], "Magnolia street is outside towards the east.", None,
             street1, ["pharmacy", "west"], "The west end of the street leads to the pharmacy.", None)


class Factory(Location):
    @call_periodically(30, 60)
    def spawn_wanderer(self, ctx: Context) -> None:
        w = Wanderer("blankly staring person", random.choice("mf"), descr="A person staring blankly somewhere.")
        w.aliases = {"person", "staring person"}
コード例 #15
0
ファイル: houses.py プロジェクト: skirtap/Tale
                         )
kitchen = Location(
    "Kitchen",
    "A small but well supplied kitchen. Rather than ordering take-away, "
    "you prefer cooking your own meals -- unlike most of the other people you know in town. A window lets you look outside."
)
kitchen.add_extradesc({
    "window", "outside"
}, "Through the kitchen window you can see your small garden and behind that, the children's playground."
                      )

#  Exits

front_door = Door(
    ["door", "outside", "street"],
    "magnolia_st.street1",
    "Your front door leads outside, to the street.",
    "There's a heavy front door here that leads to the streets outside.",
    opened=False)
house_door = front_door.reverse_door(
    ["house", "north", "inside"],
    livingroom,
    "You can go back inside your house.",
    "It's your house, on the north side of the street.",
    reverse_open_msg="Someone outside opens the door.",
    reverse_close_msg="Someone outside closes the door.",
    this_open_msg="Someone in the house opens the door.",
    this_close_msg="Someone in the house closes the door.")
livingroom.add_exits([
    Exit(
        "kitchen", kitchen, "Your kitchen is adjacent to this room.",
        "You can see your kitchen. The previous house owners had a door there but you removed it."
コード例 #16
0
ファイル: house.py プロジェクト: MitsuharuEishi/Tale
        pass

    def notify_player_arrived(self, player, previous_location):
        # player has entered!
        player.story_completed()


livingroom = Location("Living room", "The living room in your home in the outskirts of the city.")
closet = Location("Closet", "A small room.")
outside = GameEnd("Outside", "It is beautiful weather outside.")


# define the exits that connect the locations

door = Door(
    ["garden", "door"], outside,
    "A door leads to the garden.", "There's a heavy door here that leads to the garden outside the house.",
    locked=True, opened=False)
door.key_code = 1
# use an exit with an unbound target (string), the driver will link this up:
closet_exit = Exit("closet", "house.closet", "There's a small closet in your house.")
livingroom.add_exits([door, closet_exit])
# use another exit with a bound target (object):
closet.add_exits([Exit("living room", livingroom, "You can see the living room.")])


# define items and NPCs

class Cat(NPC):
    def init(self):
        self.aliases = {"cat"}
        mud_context.driver.defer(4, self.do_purr)
コード例 #17
0
ファイル: house.py プロジェクト: zaghaghi/Tale
        raise StoryCompleted


livingroom = Location(
    "Living room",
    "The living room in your home in the outskirts of the city.")
closet = Location("Closet", "A small room.")
outside = GameEnd("Outside", "It is beautiful weather outside.")

# define the exits that connect the locations

door = Door(
    ["garden", "door"],
    outside,
    "A door leads to the garden.",
    "There's a heavy door here that leads to the garden outside the house.",
    locked=True,
    opened=False,
    key_code="1"
)  # oneway door, once outside you're finished, so no reason to go back in
door.enter_msg = "You step through your garden door into the great unknown that is the outside."
livingroom.add_exits([door])

Exit.connect(livingroom, "closet", "There's a small closet in your house.", "",
             closet, ["living room", "back"],
             "You can see the living room where you came from.", "")

# define items and NPCs


class Cat(Living):
コード例 #18
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
    def test_actions(self):
        player = Player("julie", "f")
        hall = Location("hall")
        attic = Location("attic")
        unbound_exit = Exit("random", "foo.bar", "a random exit")
        with self.assertRaises(Exception):
            self.assertFalse(unbound_exit.allow_passage(
                player))  # should fail because not bound
        exit1 = Exit("ladder", attic, "first ladder to attic")
        exit1.allow_passage(player)

        door = Door("north",
                    hall,
                    "open unlocked door",
                    locked=False,
                    opened=True)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # fail, it's already open
        self.assertEqual("It's already open.", str(x.exception))
        door.close(player)
        self.assertFalse(door.opened, "must be closed")
        with self.assertRaises(ActionRefused) as x:
            door.lock(player)  # default door can't be locked
        self.assertEqual("You don't seem to have the means to lock it.",
                         str(x.exception))
        with self.assertRaises(ActionRefused) as x:
            door.unlock(player)  # fail, it's not locked
        self.assertEqual("It's not locked.", str(x.exception))

        door = Door("north",
                    hall,
                    "open locked door",
                    locked=False,
                    opened=True)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # fail, it's already open
        self.assertEqual("It's already open.", str(x.exception))
        door.close(player)
        door.locked = True
        with self.assertRaises(ActionRefused) as x:
            door.lock(player)  # it's already locked
        self.assertEqual("It's already locked.", str(x.exception))
        self.assertTrue(door.locked)
        with self.assertRaises(ActionRefused) as x:
            door.unlock(player)  # you can't unlock it
        self.assertEqual("You don't seem to have the means to unlock it.",
                         str(x.exception))
        self.assertTrue(door.locked)

        door = Door("north",
                    hall,
                    "closed unlocked door",
                    locked=False,
                    opened=False)
        door.open(player)
        self.assertTrue(door.opened)
        door.close(player)
        self.assertFalse(door.opened)
        with self.assertRaises(ActionRefused) as x:
            door.close(player)  # it's already closed
        self.assertEqual("It's already closed.", str(x.exception))

        door = Door("north",
                    hall,
                    "closed locked door",
                    locked=True,
                    opened=False)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # can't open it, it's locked
        self.assertEqual("You try to open it, but it's locked.",
                         str(x.exception))
        with self.assertRaises(ActionRefused) as x:
            door.close(player)  # it's already closed
        self.assertEqual("It's already closed.", str(x.exception))

        door = Door("north", hall, "Some door.")
        self.assertEqual("Some door.", door.short_description)
        self.assertEqual("Some door. It is open and unlocked.",
                         door.description)
        self.assertTrue(door.opened)
        self.assertFalse(door.locked)
        door = Door("north", hall, "Some door.",
                    "This is a peculiar door leading north.")
        self.assertEqual("Some door.", door.short_description)
        self.assertEqual(
            "This is a peculiar door leading north. It is open and unlocked.",
            door.description)
コード例 #19
0
ファイル: house.py プロジェクト: Ianax/Tale
 {
     'location': {
         'name': "Living room",
         'descr': "The living room in your home in the new testing story."
     },
     'exits': [
         Exit(directions="closet",
              target_location="house.closet",
              short_descr="There's a small closet in your house.",
              long_descr=None),
     ],
     'doors': [
         Door(directions=["garden", "door"],
              target_location="house.outside",
              short_descr="A door leads to the garden.",
              long_descr="There's a heavy door in this test.",
              locked=True,
              opened=False,
              key_code="1"),
         Door(
             directions=["bathroom"],
             target_location="house.bathroom",
             short_descr="A door leads to the bathroom.",
             long_descr=None,
             locked=False,
             opened=False,
             key_code=None,
         )
     ],
     'objects': []
 },
コード例 #20
0
import random
from tale.base import Location, Exit, Door, Item, Living
from tale.util import call_periodically, Context
from zones.npcs import Zombie, Trader
from zones import house

street1 = Location(
    "Lake Drive", "Your house is on Lake Drive, it overlooks the lake. "
    "The rest of the town lies eastwards.")
lot = Location("Parking Lot",
               "A small parking lot with a few cars parked in it.")

Door.connect(
    house.livingroom, ["door", "outside", "street"],
    "Your front door leads outside, to the street.\n",
    "There's a heavy front door here that leads to the streets outside.",
    street1, ["house", "door", "inside"], "You can go back inside your house.",
    "It's your house, on the north side of the street.")

deli = Location(
    "Deli",
    "A deli. It is completely empty, all the food and items seem to be gone.")

Exit.connect(deli, ["lake drive", "outside", "street", "back"],
             "Lake drive is the street you came from.", None, street1,
             ["deli", "east"], "The east end of the street leads to a deli.",
             None)
Exit.connect(lot, ["back"], "Go back home.", None, street1, ["lot", "parking"],
             "There is a parking lot next to the deli.", None)

zombie = w = Zombie("zombie",
コード例 #21
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
 def test_state(self):
     Door("out", "xyz", "short desc", locked=False, opened=False)
     Door("out", "xyz", "short desc", locked=False, opened=True)
     Door("out", "xyz", "short desc", locked=True, opened=False)
     with self.assertRaises(ValueError):
         Door("out", "xyz", "short desc", locked=True, opened=True)
コード例 #22
0
ファイル: magnolia_st.py プロジェクト: skirtap/Tale
pharmacy = Location("Pharmacy", "A pharmacy.")
pharmacy.add_exits([
    Exit(["east", "outside", "street"], street1, "Magnolia street is outside towards the east.")
])

factory = Location("ArtiGrow factory", "This area is the ArtiGrow fertilizer factory.")
factory.add_exits([
    Exit(["west", "street"], street3, "You can leave the factory to the west, back to Magnolia Street.")
])


street1.add_exits([
    houses.house_door,
    Exit(["pharmacy", "west"], pharmacy, "The west end of the street leads to the pharmacy."),
    Exit(["town", "east"], street2, "The street extends eastwards, towards the rest of the town.")
])

playground_gate = Door(["north", "gate", "playground"], "rose_st.playground", "To the north there is a small gate that connects to the children's playground.", opened=False)
street_gate = playground_gate.reverse_door(["gate", "south"], street2, "The gate that leads back to Magnolia Street is south.")
street2.add_exits([
    Exit(["west"], street1, "The street extends to the west, where your house is."),
    Exit(["east", "crossing"], "rose_st.crossing", "There's a crossing to the east."),
    Exit(["south", "house", "neighbors"], houses.neighbors_house, "You can see the house from the neighbors across the street, to the south."),
    playground_gate
])

street3.add_exits([
    Exit(["factory", "east"], factory, "Eastwards you'll enter the ArtiGrow factory area."),
    Exit(["west", "crossing"], "rose_st.crossing", "There's a crossing to the west.")
])
コード例 #23
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
 def test_with_key(self):
     player = Player("julie", "f")
     key = Key("key", "door key")
     key.key_for(code=12345)
     hall = Location("hall")
     door = Door("north", hall, "a locked door", locked=True, opened=False)
     door2 = Door("south",
                  hall,
                  "another locked door",
                  locked=True,
                  opened=False)
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     with self.assertRaises(ActionRefused):
         door.unlock(player, key)
     door.key_code = 12345
     door2.key_code = 9999
     key.key_for(door)
     self.assertTrue(door.locked)
     door.unlock(player, key)
     self.assertFalse(door.locked)
     with self.assertRaises(ActionRefused):
         door2.unlock(key)
     door.locked = True
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     key.move(player, player)
     door.unlock(player)
     self.assertFalse(door.locked)
     door.lock(player)
     self.assertTrue(door.locked)
     door.unlock(player)
     player.remove(key, player)
     with self.assertRaises(ActionRefused):
         door.lock(player)
     door.key_code = None
     with self.assertRaises(LocationIntegrityError):
         key.key_for(door)
コード例 #24
0
ファイル: house.py プロジェクト: irmen/Tale
        # player has entered, and thus the story ends
        player.tell("\n")
        player.tell("\n")
        player.tell("<bright>Congratulations on escaping the house!</> Someone else has to look after Garfield now though...")
        raise StoryCompleted


livingroom = Location("Living room", "The living room in your home in the outskirts of the city.")
closet = Location("Closet", "A small room.")
outside = GameEnd("Outside", "It is beautiful weather outside.")


# define the exits that connect the locations

door = Door(
    ["garden", "door"], outside,
    "A door leads to the garden.", "There's a heavy door here that leads to the garden outside the house.",
    locked=True, opened=False, key_code="1")    # oneway door, once outside you're finished, so no reason to go back in
door.enter_msg = "You step through your garden door into the great unknown that is the outside."
livingroom.add_exits([door])

Exit.connect(livingroom, "closet", "There's a small closet in your house.", "",
             closet, ["living room", "back"], "You can see the living room where you came from.", "")


# define items and NPCs

class Cat(Living):
    def init(self) -> None:
        self.aliases = {"cat"}

    @call_periodically(5, 20)
コード例 #25
0
ファイル: rose_st.py プロジェクト: skirtap/Tale
north_street = Location("Rose Street", "The northern part of Rose Street.")
south_street = Location("Rose Street", "The southern part of Rose Street.")

crossing = Location("Crossing", "Town Crossing.")
crossing.add_exits([
    Exit("west", "magnolia_st.street2", "Westwards lies Magnolia Street."),
    Exit("east", "magnolia_st.street3", "Magnolia Street extends to the east, eventually leading towards the factory."),
    Exit("north", north_street, "A part of Rose Street lies to the north."),
    Exit("south", south_street, "Rose Street continues to the south.")
])

playground = Location("Playground", "Children's playground. You see a rusty merry-go-round, and a little swing. "
                                    "To the west, a house is visible.")
playground.add_extradesc({"west", "house"}, "You can see your house from here!")
playground.add_exits([
    Door("fence", _limbo, "On the north end of the playground is a sturdy looking padlocked fence.", locked=True, opened=False),  # this door is never meant to be opened
    Exit(["east", "street"], north_street, "Rose Street is back east."),
    zones.magnolia_st.street_gate
])

carpark = Location("Car Parking", "There are a few cars still parked over here. Their owners are nowhere to be seen. "
                                  "One yellow car grabs your attention.")
carpark.add_extradesc({"cars"}, "They look abandoned, but their doors are all locked.")
carpark.add_extradesc({"car", "yellow"}, "It is a small two seater!")
carpark.add_exits([
    Exit(["gate", "street"], north_street, "Rose street is back through the gate.")
])

parking_gate = Door(["gate", "parking"], carpark, "Through the iron gate you can see the car parking. A few cars are still parked there, it seems.", locked=True, opened=False)
parking_gate.key_code = 111
コード例 #26
0
    def test_actions(self):
        player = Player("julie", "f")
        hall = Location("hall")
        attic = Location("attic")
        unbound_exit = Exit("random", "foo.bar", "a random exit")
        with self.assertRaises(Exception):
            self.assertFalse(unbound_exit.allow_passage(player))  # should fail because not bound
        exit1 = Exit("ladder", attic, "first ladder to attic")
        exit1.allow_passage(player)

        door = Door("north", hall, "open unlocked door", locked=False, opened=True)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # fail, it's already open
        self.assertEqual("It's already open.", str(x.exception))
        door.close(player)
        self.assertFalse(door.opened, "must be closed")
        with self.assertRaises(ActionRefused) as x:
            door.lock(player)  # default door can't be locked
        self.assertEqual("You don't seem to have the means to lock it.", str(x.exception))
        with self.assertRaises(ActionRefused) as x:
            door.unlock(player)  # fail, it's not locked
        self.assertEqual("It's not locked.", str(x.exception))

        door = Door("north", hall, "open locked door", locked=False, opened=True)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # fail, it's already open
        self.assertEqual("It's already open.", str(x.exception))
        door.close(player)
        door.locked = True
        with self.assertRaises(ActionRefused) as x:
            door.lock(player)  # it's already locked
        self.assertEqual("It's already locked.", str(x.exception))
        self.assertTrue(door.locked)
        with self.assertRaises(ActionRefused) as x:
            door.unlock(player)  # you can't unlock it
        self.assertEqual("You don't seem to have the means to unlock it.", str(x.exception))
        self.assertTrue(door.locked)

        door = Door("north", hall, "closed unlocked door", locked=False, opened=False)
        door.open(player)
        self.assertTrue(door.opened)
        door.close(player)
        self.assertFalse(door.opened)
        with self.assertRaises(ActionRefused) as x:
            door.close(player)  # it's already closed
        self.assertEqual("It's already closed.", str(x.exception))

        door = Door("north", hall, "closed locked door", locked=True, opened=False)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # can't open it, it's locked
        self.assertEqual("You try to open it, but it's locked.", str(x.exception))
        with self.assertRaises(ActionRefused) as x:
            door.close(player)  # it's already closed
        self.assertEqual("It's already closed.", str(x.exception))

        door = Door("north", hall, "Some door.")
        self.assertEqual("Some door.", door.short_description)
        self.assertEqual("Some door. It is open and unlocked.", door.description)
        self.assertTrue(door.opened)
        self.assertFalse(door.locked)
        door = Door("north", hall, "Some door.", "This is a peculiar door leading north.")
        self.assertEqual("Some door.", door.short_description)
        self.assertEqual("This is a peculiar door leading north. It is open and unlocked.", door.description)
コード例 #27
0
ファイル: house.py プロジェクト: jordanaycamara/Tale
        pass

    def notify_player_arrived(self, player, previous_location):
        # player has entered!
        player.story_completed()


livingroom = Location("Living room", "The living room in your home in the outskirts of the city.")
closet = Location("Closet", "A small room.")
outside = GameEnd("Outside", "It is beautiful weather outside.")


# define the exits that connect the locations

door = Door(
    ["garden", "door"], outside,
    "A door leads to the garden.", "There's a heavy door here that leads to the garden outside the house.",
    locked=True, opened=False)
door.door_code = 1
closet_exit = Exit("closet", closet, "There's a small closet in your house.")
livingroom.add_exits([door, closet_exit])
closet.add_exits([Exit("living room", livingroom, "You can see the living room.")])


# define items and NPCs

class Cat(NPC):
    def init(self):
        self.aliases={"cat"}
        mud_context.driver.defer(4, self, self.do_purr)

    def do_purr(self, driver):
コード例 #28
0
 def test_with_key(self):
     player = Player("julie", "f")
     key = Item("key", "door key")
     key.door_code = 12345
     hall = Location("hall")
     door = Door("north", hall, "a locked door", locked=True, opened=False)
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     with self.assertRaises(ActionRefused):
         door.unlock(player, key)
     door.door_code = 12345
     self.assertTrue(door.locked)
     door.unlock(player, key)
     self.assertFalse(door.locked)
     door.locked = True
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     key.move(player, player)
     door.unlock(player)
     self.assertFalse(door.locked)
     door.lock(player)
     self.assertTrue(door.locked)
コード例 #29
0
crossing = Location("Crossing", "Town Crossing.")
crossing.add_exits([
    Exit("west", "magnolia_st.street2", "Westwards lies Magnolia Street."),
    Exit("east", "magnolia_st.street3", "Magnolia Street extends to the east, eventually leading towards the factory."),
])

Exit.connect(crossing, "north", "A part of Rose Street lies to the north.", None,
             north_street, ["south", "crossing"], "The street goes south towards the crossing.", None)
Exit.connect(crossing, "south", "Rose Street continues to the south.", None,
             south_street, ["north", "crossing"], "The crossing is back towards the north.", None)

playground = Location("Playground", "Children's playground. You see a rusty merry-go-round, and a little swing. "
                                    "To the west, a house is visible.")
playground.add_extradesc({"west", "house"}, "You can see your house from here!")
playground.add_exits([
    Door("fence", _limbo, "On the north end of the playground is a sturdy looking padlocked fence.",
         locked=True, opened=False, key_code="999999999"),  # this door is never meant to be opened
])

Exit.connect(playground, ["east", "street"], "Rose Street is back east.", None,
             north_street, ["west", "playground"], "The children's playground is to the west.", None)


class CarPark(Location):
    def init(self):
        self.verbs = {"drive": "Drive a car",
                      "open": "Open something",
                      "enter": "Enter something",
                      "sit": "Sit somewhere",
                      "use": "Use something",
                      "start": "Start something"
                      }
コード例 #30
0
from tale.util import call_periodically, Context
from zones import houses, rose_st
from zones.npcs import Apothecary, Wanderer

street1 = Location(
    "Magnolia Street",
    "Your house is on Magnolia Street, one of the larger streets in town. "
    "The rest of the town lies eastwards.")
street2 = Location("Magnolia Street", "Another part of the street.")
street3 = Location("Magnolia Street (east)",
                   "The eastern part of Magnolia Street.")

Door.connect(
    houses.livingroom, ["door", "outside", "street"],
    "Your front door leads outside, to the street.",
    "There's a heavy front door here that leads to the streets outside.",
    street1, ["house", "north", "inside"],
    "You can go back inside your house.",
    "It's your house, on the north side of the street.")

pharmacy = Location(
    "Pharmacy", "A pharmacy. It is completely empty, all medicine seems gone.")

Exit.connect(pharmacy, ["east", "outside", "street"],
             "Magnolia street is outside towards the east.", None, street1,
             ["pharmacy", "west"],
             "The west end of the street leads to the pharmacy.", None)


class Factory(Location):
    @call_periodically(30, 60)