本文整理汇总了Python中tale.base.Location.handle_verb方法的典型用法代码示例。如果您正苦于以下问题:Python Location.handle_verb方法的具体用法?Python Location.handle_verb怎么用?Python Location.handle_verb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tale.base.Location
的用法示例。
在下文中一共展示了Location.handle_verb方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_handle_and_notify_action
# 需要导入模块: from tale.base import Location [as 别名]
# 或者: from tale.base.Location import handle_verb [as 别名]
def test_handle_and_notify_action(self):
class SpecialPlayer(Player):
def init(self):
self.handled = False
self.handle_verb_called = False
self.notify_called = False
def handle_verb(self, parsed, actor):
self.handle_verb_called = True
if parsed.verb in self.verbs:
self.handled = True
return True
else:
return False
def notify_action(self, parsed, actor):
self.notify_called = True
player = SpecialPlayer("julie", "f")
player.verbs["xywobble"] = ""
room = Location("room")
class Chair(Item):
def init(self):
self.handled = False
self.handle_verb_called = False
self.notify_called = False
def handle_verb(self, parsed, actor):
self.handle_verb_called = True
if parsed.verb in self.verbs:
self.handled = True
return True
else:
return False
def notify_action(self, parsed, actor):
self.notify_called = True
chair_in_inventory = Chair("littlechair")
chair_in_inventory.verbs["kerwaffle"] = ""
player.insert(chair_in_inventory, player)
chair = Chair("chair")
chair.verbs["frobnitz"] = ""
room.init_inventory([player, chair])
# first check if the handle_verb passes to all objects including inventory
parsed = ParseResult("kowabungaa12345")
handled = room.handle_verb(parsed, player)
self.assertFalse(handled)
self.assertTrue(chair.handle_verb_called)
self.assertTrue(player.handle_verb_called)
self.assertTrue(chair_in_inventory.handle_verb_called)
self.assertFalse(chair.handled)
self.assertFalse(player.handled)
self.assertFalse(chair_in_inventory.handled)
# check item handling
player.init()
chair.init()
chair_in_inventory.init()
parsed = ParseResult("frobnitz")
handled = room.handle_verb(parsed, player)
self.assertTrue(handled)
self.assertTrue(chair.handled)
self.assertFalse(player.handled)
self.assertFalse(chair_in_inventory.handled)
# check living handling
player.init()
chair.init()
chair_in_inventory.init()
parsed = ParseResult("xywobble")
handled = room.handle_verb(parsed, player)
self.assertTrue(handled)
self.assertFalse(chair.handled)
self.assertTrue(player.handled)
self.assertFalse(chair_in_inventory.handled)
# check inventory handling
player.init()
chair.init()
chair_in_inventory.init()
parsed = ParseResult("kerwaffle")
handled = room.handle_verb(parsed, player)
self.assertTrue(handled)
self.assertFalse(chair.handled)
self.assertFalse(player.handled)
self.assertTrue(chair_in_inventory.handled)
# check notify_action
player.init()
chair.init()
chair_in_inventory.init()
room.notify_action(parsed, player)
self.assertTrue(chair.notify_called)
self.assertTrue(player.notify_called)
self.assertTrue(chair_in_inventory.notify_called)