def test_clone(self): item = Item("thing", "description") item.aliases = ["a1", "a2"] item2 = util.clone(item) self.assertNotEqual(item, item2) item2.aliases.append("a3") self.assertNotEqual(item.aliases, item2.aliases) player = Player("julie", "f") player.insert(item, player) player2 = util.clone(player) player2.insert(item2, player2) self.assertNotEqual(player.inventory_size, player2.inventory_size) self.assertNotEqual(player.inventory, player2.inventory) self.assertTrue(item in player) self.assertFalse(item in player2)
def test_clone(self): item = Item("thing", "description") item.aliases = ["a1", "a2"] item2 = clone(item) self.assertNotEqual(item, item2) item2.aliases.append("a3") self.assertNotEqual(item.aliases, item2.aliases) player = Player("julie", "f") player.insert(item, player) with self.assertRaises(ValueError): clone(player) # can't clone something with stuff in it player.remove(item, player) player2 = clone(player) player2.insert(item2, player2) self.assertNotEqual(player.inventory_size, player2.inventory_size) self.assertNotEqual(player.inventory, player2.inventory) self.assertFalse(item in player) self.assertFalse(item in player2)
def insert(self, item: Union[Living, Item], actor: Optional[Living]) -> None: raise ActionRefused( "No matter how hard you try, you can't fit %s in the box." % item.title) insertonly_box = InsertOnlyBox("box1", "box1 (a black box)") removeonly_box = RemoveOnlyBox("box2", "box2 (a white box)") normal_gem = gem.clone() removeonly_box.init_inventory([normal_gem]) cursed_gem = CursedGem("black gem") cursed_gem.aliases = {"gem"} normal_gem = Item("blue gem") normal_gem.aliases = {"gem"} lane.add_exits([ Exit(["shop", "north east", "northeast", "ne"], "shoppe.shop", "There's a curiosity shop to the north-east.") ]) class WizardTowerEntry(Exit): def allow_passage(self, actor: Living) -> None: if "wizard" in actor.privileges: actor.tell("You pass through the force-field.", end=True) else: raise ActionRefused( "You can't go that way, the force-field is impenetrable.")
class Glasses(Wearable): def init(self, wearing=False): super(Glasses, self).init() self.wearing = wearing def wearing_glasses(self): while self.wearing: pass def vision_problems(self): pass glasses = Item("glasses", "glasses", "pair of ladies eyeglasses.") glasses.aliases = {"glasses"} glasses.add_extradesc({"glasses"}, "The horn-rimmed glasses aren't really your style.") glasses_case = GlassesCase("case", "clamshell case for eyeglasses") glasses_case.aliases = {"case", "clamshell case", "eyeglasses case"} glasses_case.init_inventory([glasses]) gym.init_inventory([glasses_case]) freshman = NPC("freshman", "m", title="freshman", description="It's a freshman. They all look the same.") # sawdust = Item("sawdust", "sawdust") # sawdust.add_extradesc({"sawdust", "pink sawdust"}, "It's pink sawdust, the kind used to soak up spills and messes.") # bucket = Container("bucket", "bucket") # bucket.add_extradesc({"bucket"}, "You see an ordinary blue plastic bucket.")
raise ActionRefused("The box is cursed! You can't take anything out of it!") class RemoveOnlyBox(Container): def insert(self, item, actor): raise ActionRefused("No matter how hard you try, you can't fit %s in the box." % item.title) insertonly_box = InsertOnlyBox("box1", "box1 (a black box)") removeonly_box = RemoveOnlyBox("box2", "box2 (a white box)") normal_gem = clone(gem) removeonly_box.init_inventory([normal_gem]) cursed_gem = CursedGem("black gem", "a black gem") cursed_gem.aliases={"gem"} normal_gem = Item("blue gem", "a blue gem") normal_gem.aliases={"gem"} lane.add_exits([Exit("south", square, "The town square lies to the south.")]) class WizardTowerEntry(Exit): def allow_passage(self, actor): if "wizard" in actor.privileges: actor.tell("You pass through the force-field.") else: raise ActionRefused("You can't go that way, the force-field is impenetrable.") lane.add_exits([WizardTowerEntry("west", "wizardtower.hall", "To the west is the wizard's tower. It seems to be protected by a force-field.")]) towncrier = TownCrier("laish", "f", title="Laish the town crier", description="The town crier of Essglen is awfully quiet today. She seems rather preoccupied with something.") towncrier.aliases = {"crier", "town crier"}
Door.connect(street2, ["north", "gate", "playground"], "To the north there is a small gate that connects to the children's playground.", None, rose_st.playground, ["gate", "south"], "The gate that leads back to Magnolia Street is south.", None) Exit.connect(street2, ["south", "house", "neighbors"], "You can see the house from the neighbors across the street, to the south.", None, houses.neighbors_house, ["street", "north"], "The street is back north.", None) street2.add_exits([ Exit(["east", "crossing"], "rose_st.crossing", "There's a crossing to the east."), ]) street3.add_exits([ Exit(["west", "crossing"], "rose_st.crossing", "There's a crossing to the west.") ]) apothecary = Apothecary("carla", "f", title="apothecary Carla") apothecary.extra_desc["bottle"] = "It is a small bottle of the pills that your friend Peter needs for his illness." apothecary.extra_desc["pills"] = apothecary.extra_desc["bottle"] apothecary.aliases.add("apothecary") # the medicine Peter needs medicine = Item("pills", "bottle of pills", descr="It looks like the medicine your friend Peter needs for his illness.") medicine.value = Apothecary.pills_price medicine.aliases = {"bottle", "medicine"} apothecary.init_inventory([medicine]) pharmacy.insert(apothecary, None)
"clean": "Clean up the puke.", "cover": "Clean up the puke." # "put": "Put something on something else.", } vomit.add_extradesc( {"puddle", "sick", "vomit", "puke"}, """ Someone appears to have had tummy troubles; a puddle of sick lies in the middle of the corridor. The puddle is . . . kinda gross. It was Salisbury Steak Day. """, ) south_hallway.init_inventory([vomit]) english_paper = Item("english homework", "english paper") english_paper.aliases = {"english paper", "paper", "homework"} english_paper.add_extradesc({"paper", "english paper", "homework"}, "You paid good money for this!") class Locker(Boxlike): def init(self, locked=True, opened=False, combo="8-16-32"): super(Boxlike, self).init() self.txt_title_closed = self._title self.txt_title_open_filled = self._title self.txt_title_open_empty = "empty " + self._title self.txt_descr_closed = "The locker is closed." self.txt_descr_open_filled = "There's something inside {}.".format(self._title) self.txt_descr_open_empty = "There's nothing inside {}.".format(self._title) self.locked = locked self.opened = opened self.combo = combo # you can optionally set this to any code that a key must match to unlock the door
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", random.choice("mf"), descr="A bloody zombie lingering around.") street1.insert(zombie, None) trader = Trader("Creepy Trader", "m", title="Creepy Trader") trader.extra_desc[ "bullets"] = "It is a a box of rounds with 5 bullets in it for your gun." trader.extra_desc["ammo"] = trader.extra_desc["bullets"] trader.aliases.add("trader") # ammo ammo = Item("ammo", "5 pistol bullets", descr="It looks like the ammo for your gun.") ammo.value = Trader.ammo_price ammo.aliases = {"bullets", "ammo"} trader.init_inventory([ammo]) deli.insert(trader, None)
"You can see the house from the neighbors across the street, to the south.", None, houses.neighbors_house, ["street", "north"], "The street is back north.", None) street2.add_exits([ Exit(["east", "crossing"], "rose_st.crossing", "There's a crossing to the east."), ]) street3.add_exits([ Exit(["west", "crossing"], "rose_st.crossing", "There's a crossing to the west.") ]) apothecary = Apothecary("carla", "f", title="apothecary Carla") apothecary.extra_desc[ "bottle"] = "It is a small bottle of the pills that your friend Peter needs for his illness." apothecary.extra_desc["pills"] = apothecary.extra_desc["bottle"] apothecary.aliases.add("apothecary") # the medicine Peter needs medicine = Item( "pills", "bottle of pills", descr="It looks like the medicine your friend Peter needs for his illness." ) medicine.value = Apothecary.pills_price medicine.aliases = {"bottle", "medicine"} apothecary.init_inventory([medicine]) pharmacy.insert(apothecary, None)