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


Python World.onEvent方法代码示例

本文整理汇总了Python中xatro.world.World.onEvent方法的典型用法代码示例。如果您正苦于以下问题:Python World.onEvent方法的具体用法?Python World.onEvent怎么用?Python World.onEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xatro.world.World的用法示例。


在下文中一共展示了World.onEvent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_onEvent_cancel

# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import onEvent [as 别名]
    def test_onEvent_cancel(self):
        """
        You can cancel the deferred returned by onEvent
        """
        world = World(MagicMock())

        obj = world.create('foo')

        d = world.onEvent(obj['id'], 'hey')
        d.cancel()

        world.emit('hey', obj['id'])

        self.assertFailure(d, defer.CancelledError)
开发者ID:iffy,项目名称:xatrobots,代码行数:16,代码来源:test_world.py

示例2: test_onEvent

# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import onEvent [as 别名]
    def test_onEvent(self):
        """
        You can be notified when a certain event happens.
        """
        world = World(MagicMock())

        obj = world.create('foo')['id']

        d = world.onEvent(obj, 'event')
        self.assertEqual(d.called, False)

        world.emit('event', obj)
        self.assertEqual(self.successResultOf(d), 'event')

        # shouldn't die calling again
        world.emit('event', obj)
开发者ID:iffy,项目名称:xatrobots,代码行数:18,代码来源:test_world.py

示例3: test_creator_dead

# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import onEvent [as 别名]
    def test_creator_dead(self):
        """
        When the creator of energy is dead, the energy is also dead.

        XXX I'm not sure if this belongs in the game engine or not.  Seems like
        a rule that could be changed.
        """
        world = World(MagicMock())
        thing = world.create('thing')

        Charge(thing['id']).execute(world)

        energy = thing['energy'][0]
        d = world.onEvent(energy, Destroyed(energy))

        # to die means to move to None
        Move(thing['id'], None).execute(world)

        self.assertEqual(d.called, True, "Energy should be destroyed because "
                         "the creator of the energy died.")
开发者ID:iffy,项目名称:xatrobots,代码行数:22,代码来源:test_action.py


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