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)
# 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): if random.random() > 0.5: self.location.tell("%s purrs happily." % capital(self.title))