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


Python Level.execute_on_event方法代码示例

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


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

示例1: parse

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import execute_on_event [as 别名]
    def parse(self, line):
        line = line.strip()
        level = Level()
        if line.startswith('entity'):
            cmd, entity = line.split(' ')
            level.execute_entity(entity)
            
        if line.startswith('state'):
            cmd, entity, state = line.split(' ')
            level.execute_state(entity, state)
            
        if line.startswith('on_event'):
            lvalue, rvalue = line.split(':')
            cmd, entity, event = lvalue.split(' ')
            commands = []
            curr_command, separator, rvalue = rvalue.partition(',')
            commands.append(curr_command)
            while separator==",":
                curr_command, separator, rvalue = rvalue.partition(',')
                commands.append(curr_command)
            level.execute_on_event(entity, event, commands)

        if line.startswith('trans'):
            firstpart, secondpart = line[6:].split(',')
            old_mapstatus = self.parse_mapstatus(firstpart.strip())
            new_mapstatus = self.parse_mapstatus(secondpart.strip())
            if old_mapstatus['c'][0] not in self.trans:
                self.trans[old_mapstatus['c'][0]] = list()
            self.trans[old_mapstatus['c'][0]].append((old_mapstatus, new_mapstatus))
开发者ID:denever,项目名称:lettere,代码行数:31,代码来源:rule_parser.py

示例2: parse

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import execute_on_event [as 别名]
    def parse(self, line):
        line = line.strip()
        level = Level()

        if line.startswith('entity'):
            cmd, entity = line.split(' ')
            level.execute_entity(entity)
            
        if line.startswith('state'):
            cmd, entity, state = line.split(' ')
            level.execute_state(entity, state)
            
        if line.startswith('on_event'):
            lvalue, rvalue = line.split(':')
            cmd, entity, event = lvalue.split(' ')
            commands = []
            curr_command, separator, rvalue = rvalue.partition(',')
            commands.append(curr_command)
            while separator==",":
                curr_command, separator, rvalue = rvalue.partition(',')
                commands.append(curr_command)
            level.execute_on_event(entity, event, commands)

        if line.startswith('trans'):
            firstpart, secondpart = line[6:].split(',')
            old_mapstatus = self.parse_mapstatus(firstpart.strip())
            new_mapstatus = self.parse_mapstatus(secondpart.strip())
            if old_mapstatus['c'][0] not in self.trans:
                self.trans[old_mapstatus['c'][0]] = list()
            self.trans[old_mapstatus['c'][0]].append((old_mapstatus, new_mapstatus))

        if line.startswith('set name'):
            level.execute_set_map_title(line[10:-2])

        if line.startswith('set author'):
            level.execute_set_map_author(line[12:-2])

        if line.startswith('set maxtime'):
            level.execute_set_maxtime(int(line[12:-1]))

        if line.startswith('set minscore'):
            level.execute_set_minscore(int(line[13:-1]))

        if line.startswith('get name'):
            level.execute_get_map_title()

        if line.startswith('get author'):
            level.execute_get_map_author()

        if line.startswith('get maxtime'):
            level.execute_get_maxtime()

        if line.startswith('get minscore'):
            level.execute_get_minscore()

        if line.startswith('put'):
            cmd, entity, pos = line.split(' ')
            y, x = eval(pos[1:-2])
            level.execute_put(entity, x, y)
        
        if line.startswith('line'):
            cmd, entity, pos = line.split(' ')
            if not entity in self.entities:
                return "Can't set unknown entity %s" % entity
            pos = pos.replace(')(',',')
            x1, y1, x2, y2 = eval(pos[1:-2])
            level.execute_line(entity, x1, y1, x2, y2)

        if line.startswith('rect'):
            cmd, entity, pos = line.split(' ')
            if not entity in self.entities:
                return "Can't set unknown entity %s" % entity
            pos = pos.replace(')(',',')
            x1, y1, height, width = eval(pos[1:-2])
            level.execute_rect(entity, x1, y1, height, width)

        if line.startswith('play'):
            cmd, space, args = line.partition(' ')
            level.execute_play(args)

        if line.startswith('move'):
            cmd, direction, n_pixels, entity_id = line.split(' ', 3)
            level.execute_move(int(entity_id), direction, int(n_pixels))

        if line.startswith('add_score'):
            cmd, n_scores = line.split(' ', 1)
            level.execute_add_score(int(n_scores))
开发者ID:denever,项目名称:lettere,代码行数:89,代码来源:gsl_parser.py


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