當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。