本文整理匯總了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)