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)
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)
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)
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)
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 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
# 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) def do_purr(self, ctx):