本文整理汇总了Python中tale.base.Location.get_wiretap方法的典型用法代码示例。如果您正苦于以下问题:Python Location.get_wiretap方法的具体用法?Python Location.get_wiretap怎么用?Python Location.get_wiretap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tale.base.Location
的用法示例。
在下文中一共展示了Location.get_wiretap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_door_pair
# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import get_wiretap [as 别名]
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)
示例2: James
# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import get_wiretap [as 别名]
class James(NPC, Listener):
"""The customer trying to sell a Lamp, and helpful as rat deterrent."""
def pubsub_event(self, topicname, event):
if topicname[0] == "wiretap-location":
if "Rat arrives" in event[1]:
mud_context.driver.defer(2, self.rat_scream, "frown")
mud_context.driver.defer(4, self.rat_kick)
def rat_scream(self, action, ctx):
shopkeeper.do_socialize(action)
def rat_kick(self, ctx):
rat = self.location.search_living("rat")
if rat:
self.do_socialize("kick rat")
rat.do_socialize("recoil")
direction = rat.select_random_move()
if direction:
rat.tell_others("{Title} runs away towards the door!")
rat.move(direction.target, self)
mud_context.driver.defer(2, self.rat_scream, "smile at " + self.name)
customer = James("James", "m", title="Sir James", description="Sir James is trying to sell something, it looks like a lamp.")
lamp.add_extradesc({"lamp"}, "The lamp looks quite old, but otherwise is rather unremarkable. There is something weird going on with the cord though!")
lamp.add_extradesc({"cord"}, "Even when the lamp doesn't move, the power cord keeps snaking around as if it were alive. How odd.")
customer.insert(lamp, customer)
shop.insert(customer, shop)
shop.get_wiretap().subscribe(customer)