Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
                                                 "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")


butcher = Location("Butcher shop", "The town's butcher shop. Usually there's quite a few people waiting in line, but now it is deserted.")
butcher.insert(parking_key, None)
Exit.connect(butcher, ["north", "street"], "Rose street is back to the north.", None,
Ejemplo n.º 6
0
                                                 "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")


butcher = Location("Butcher shop", "The town's butcher shop. Usually there's quite a few people waiting in line, but now it is deserted.")
butcher.insert(parking_key, None)
Exit.connect(butcher, ["north", "street"], "Rose street is back to the north.", None,
Ejemplo n.º 7
0
Archivo: house.py Proyecto: Ianax/Tale
                 long_descr="A simple bathroom door.",
                 locked=False,
                 opened=False,
                 key_code=None)
        ],
        'objects': [cat]
    },
}

#
for room in rooms.keys():
    globals()[room] = Location(rooms[room]['location']['name'],
                               rooms[room]['location']['descr'])
    if 'exits' in rooms[room]:
        globals()[room].add_exits(rooms[room]['exits'])
    if 'doors' in rooms[room]:
        globals()[room].add_exits(rooms[room]['doors'])
    if 'objects' in rooms[room]:
        for thing in rooms[room]['objects']:
            globals()[room].insert(thing, None)

outside = GameEnd("Outside", "It is beautiful weather outside.")

#rooms['livingroom']['doors'][1].reverse_door(["livingroom", "out"],
#                                             "house.bathroom",
#                                             "A door leading to the living room.",
#                                             "A door leading to the living room.")

#livingroom.insert(cat, None)
key.key_for(rooms['livingroom']['doors'][0])
Ejemplo n.º 8
0
            self.tell_others("{Actor} stares at {target} incomprehensibly.",
                             target=actor)
        else:
            message = (parsed.message or parsed.unparsed).lower().split()
            if self.name in message or "cat" in message:
                self.tell_others(
                    "{Actor} looks up at {target} and wiggles %s tail." %
                    self.possessive,
                    target=actor)


cat = Cat(
    "garfield",
    "m",
    race="cat",
    descr=
    "A very obese cat, orange and black. It looks tired, but glances at you happily."
)
livingroom.insert(cat, None)
key = Key(
    "key",
    "small rusty key",
    descr=
    "This key is small and rusty. It has a label attached, reading \"garden door\"."
)
key.key_for(door)
closet.insert(key, None)

closet.insert(woodenYstick.clone(), None)
livingroom.insert(elastic_band.clone(), None)
Ejemplo n.º 9
0
        if random.random() > 0.7:
            self.location.tell("%s purrs happily." % capital(self.title))
        else:
            self.location.tell("%s yawns sleepily." % capital(self.title))
        # it's possible to stop the periodical calling by setting:  call_periodically(0)(Cat.do_purr)

    def notify_action(self, parsed: ParseResult, actor: Living) -> None:
        if actor is self or parsed.verb in self.verbs:
            return  # avoid reacting to ourselves, or reacting to verbs we already have a handler for
        if parsed.verb in ("pet", "stroke", "tickle", "cuddle", "hug", "caress", "rub"):
            self.tell_others("{Actor} curls up in a ball and purrs contently.")
        elif parsed.verb in AGGRESSIVE_VERBS:
            if self in parsed.who_info:   # only give aggressive response when directed at the cat.
                self.tell_others("{Actor} hisses! I wouldn't make %s angry if I were you!" % self.objective)
        elif parsed.verb in ("hello", "hi", "greet", "meow", "purr"):
            self.tell_others("{Actor} stares at {target} incomprehensibly.", target=actor)
        else:
            message = (parsed.message or parsed.unparsed).lower().split()
            if self.name in message or "cat" in message:
                self.tell_others("{Actor} looks up at {target} and wiggles %s tail." % self.possessive, target=actor)


cat = Cat("garfield", "m", race="cat", descr="A very obese cat, orange and black. It looks tired, but glances at you happily.")
livingroom.insert(cat, None)
key = Key("key", "small rusty key", descr="This key is small and rusty. It has a label attached, reading \"garden door\".")
key.key_for(door)
closet.insert(key, None)

closet.insert(woodenYstick.clone(), None)
livingroom.insert(elastic_band.clone(), None)
Ejemplo n.º 10
0
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

butcher = Location("Butcher shop", "The town's butcher shop. Usually there's quite a few people waiting in line, but now it is deserted.")
storage_room = Location("Storage Cell", "The butcher's meat storage cell. Brrrrr, it is cold here!")
butcher.add_exits([
    Exit(["north", "street"], south_street, "Rose street is back to the north."),
    Door(["door", "storage"], storage_room, "A door leads to the storage room.")
])
storage_room.add_exits([
    Door(["door", "shop"], butcher, "The door leads back to the shop.")
])

north_street.add_exits([
    Exit(["west", "playground"], playground, "The children's playground is to the west."),
    Exit(["south", "crossing"], crossing, "The street goes south towards the crossing."),
    parking_gate
])

south_street.add_exits([
    Exit(["north", "crossing"], crossing, "The crossing is back towards the north."),
    Exit(["south", "butcher"], butcher, "The butcher shop is to the south.")
])

parking_key = Key("key", "rusty key", "It is what appears to be an old key, with a label on it.", "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'.")

butcher.insert(parking_key, None)
Ejemplo n.º 11
0
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)

##### Closet #####
closet = Location("Closet", "A small room.")

closet_lr = Exit(
    directions=["living room", "back", "livingroom"],
    target_location="house.livingroom",
    short_descr="You can see the living room where you came from.",
    long_descr=None)

closet.add_exits([closet_lr])

closet.insert(key, None)
key.key_for(garden_door)

closet.insert(woodenYstick.clone(), None)

##### Outside #####

outside = GameEnd("Outside", "It is beautiful weather outside.")