当前位置: 首页>>代码示例>>Python>>正文


Python Location.get_wiretap方法代码示例

本文整理汇总了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)
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:37,代码来源:test_mudobjects.py

示例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)
开发者ID:MitsuharuEishi,项目名称:Tale,代码行数:31,代码来源:shoppe.py


注:本文中的tale.base.Location.get_wiretap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。