本文整理汇总了Python中tale.base.Location.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Location.insert方法的具体用法?Python Location.insert怎么用?Python Location.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tale.base.Location
的用法示例。
在下文中一共展示了Location.insert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_enter_leave
# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import insert [as 别名]
def test_enter_leave(self):
hall = Location("hall")
rat1 = NPC("rat1", "n")
rat2 = NPC("rat2", "n")
julie = NPC("julie", "f")
with self.assertRaises(TypeError):
hall.insert(12345, julie)
self.assertEqual(_Limbo, rat1.location)
self.assertFalse(rat1 in hall.livings)
wiretap = Wiretap(hall)
hall.insert(rat1, julie)
self.assertEqual(hall, rat1.location)
self.assertTrue(rat1 in hall.livings)
self.assertEqual([], wiretap.msgs, "insert shouldn't produce arrival messages")
hall.insert(rat2, julie)
self.assertTrue(rat2 in hall.livings)
self.assertEqual([], wiretap.msgs, "insert shouldn't produce arrival messages")
# now test leave
wiretap.clear()
hall.remove(rat1, julie)
self.assertFalse(rat1 in hall.livings)
self.assertIsNone(rat1.location)
self.assertEqual([], wiretap.msgs, "remove shouldn't produce exit message")
hall.remove(rat2, julie)
self.assertFalse(rat2 in hall.livings)
self.assertEqual([], wiretap.msgs, "remove shouldn't produce exit message")
# test random leave
hall.remove(rat1, julie)
hall.remove(12345, julie)
示例2: test_print_location
# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import insert [as 别名]
def test_print_location(self):
p = Player("julie", "f")
key = Item("key")
bag = Container("bag")
room = Location("room")
bag.insert(key, p)
p.insert(bag, p)
room.insert(p, p)
with self.assertRaises(Exception):
p.tell_object_location(None, None)
p.tell_object_location(key, None)
self.assertEqual(["(It's not clear where key is).\n"], p.test_get_output_paragraphs())
p.tell_object_location(key, None, print_parentheses=False)
self.assertEqual(["It's not clear where key is.\n"], p.test_get_output_paragraphs())
p.tell_object_location(key, bag)
result = "".join(p.test_get_output_paragraphs())
self.assertTrue("in bag" in result and "in your inventory" in result)
p.tell_object_location(key, room)
self.assertTrue("in your current location" in "".join(p.test_get_output_paragraphs()))
p.tell_object_location(bag, p)
self.assertTrue("in your inventory" in "".join(p.test_get_output_paragraphs()))
p.tell_object_location(p, room)
self.assertTrue("in your current location" in "".join(p.test_get_output_paragraphs()))
示例3: Cat
# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import insert [as 别名]
# 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))
else:
self.location.tell("%s yawns sleepily." % capital(self.title))
driver.defer(random.randint(5, 20), self, self.do_purr)
def notify_action(self, parsed, actor):
if parsed.verb in ("pet", "stroke", "tickle", "cuddle", "hug"):
self.tell_others("{Title} curls up in a ball and purrs contently.")
elif parsed.verb in ("hello", "hi", "greet"):
self.tell_others("{Title} stares at you incomprehensibly.")
else:
message = (parsed.message or parsed.unparsed).lower()
if self.name in message:
self.tell_others("{Title} looks up at you.")
cat = Cat("garfield", "m", race="cat", description="A very obese cat, orange and black. It looks tired, but glances at you happily.")
livingroom.insert(cat, None)
key = Item("key", "small rusty key", "This key is small and rusty. It has a label attached, reading \"garden door\".")
key.door_code = 1
closet.insert(key, None)
示例4: StorageRoom
# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import insert [as 别名]
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,
south_street, ["south", "butcher"], "The butcher shop is to the south.", None)
storage_room = StorageRoom("Storage room", "The butcher's meat storage room. Brrrrr, it is cold here!")
storage_room_door, _ = Door.connect(butcher, ["door", "storage"],
"A door leads to the storage room.",
"The meat storage is behind it. The door's locked with a security card instead of a key.",
storage_room, ["door", "shop"], "The door leads back to the shop.", None,
locked=True, key_code="butcher1")
friend = zones.npcs.Friend("Peter", "m", descr="It's your friend Peter, who works at the butcher shop.")
storage_room.insert(friend, None)
butcher_key = Key("card", "security card", descr="It is a security card, with a single word `storage' written on it.")
示例5: capital
# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import insert [as 别名]
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)
示例6: Exit
# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import insert [as 别名]
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)
示例7: init
# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import insert [as 别名]
def init(driver):
# called when zone is first loaded
pass
# create the Olde Shoppe and its owner
shopinfo = ShopBehavior()
toothpick = Item("toothpick", "pointy wooden toothpick")
toothpick.value = 0.12
shopinfo.forsale.add(toothpick)
shopinfo.banks_money = True
shopkeeper = Shopkeeper("Lucy", "f", short_description="Lucy, the shop owner, is looking happily at her newly arrived customer.")
shopkeeper.money = 14000
shop = Location("Curiosity Shoppe", "A weird little shop. It sells odd stuff.")
shop.insert(shopkeeper, shop)
shop.add_exits([Exit(["door", "out"], "town.lane", "A fancy door provides access back to the lane outside.")])
# provide some items in the shop
clock = clone(gameclock)
clock.value = 500
paper = clone(newspaper)
gem2 = clone(diamond)
gem2.value = 80000
gem3 = clone(gem)
gem3.value = 9055
shopkeeper.init_inventory([gem2, gem3, toothpick])
shopkeeper.set_shop(shopinfo)
shop.insert(clock, shop)
shop.insert(paper, shop)