Beispiel #1
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)
Beispiel #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)
Beispiel #3
0
# ----------------- 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.")
])


# ----------------- Neighbours House, Bedroom, Garden  -------------------------
Beispiel #4
0
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.")
])
Beispiel #5
0
}, "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.")
])