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


Python Arena.coords_have_class方法代码示例

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


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

示例1: GameState

# 需要导入模块: from arena import Arena [as 别名]
# 或者: from arena.Arena import coords_have_class [as 别名]
class GameState(object):

    """Represents the game state"""

    def __init__(self):
        """Simple init of variables"""
        self.arena = None

        self._player_queue = udeque()
        self._sticky_actions = {}
        self._action_queue = deque()

        self._lookup = {
            'B': Block,
            '.': DestructibleBlock,
            'S': SpawnPoint,
        }

        self._flames = []

        self.arena_load(["arenas", "default.bmm"])

    def arena_load(self, filename_list):
        """Load an arena from a file"""
        lines = []

        with codecs.open(os.sep.join(filename_list), 'r', 'UTF-8') as fp:
            for line in fp:
                lines.append(line.rstrip())

        self.arena = Arena(max((len(line) for line in lines)), len(lines))

        for row, line in enumerate(lines):
            for col, char in enumerate(line):
                if char == ' ':
                    continue

                self._lookup[char](state=self, coords=(col, row))

    def __str__(self):
        """Produce a string representation of the arena in the same format as the map files"""
        chars = []
        old_y = 0
        for _, y, l in self.arena:
            if y != old_y:
                chars.append('\n')
                old_y = y

            chars.append(str(max(l + [GameObject(state=None, coords=None)],
                                 key=lambda o: o.ZINDEX)))

        chars.append('\n')

        return ''.join(chars)

    def __repr__(self):
        return str(self)

    def player_add(self, player):
        """Add a player to the game state"""
        self._player_queue.appendleft(player)

    def player_remove(self, player):
        """Remove a player from the game state"""
        player.remove()

    def spawn(self):
        """Spawn the players into the arena"""
        p_no = 0
        for x, y, _ in self.arena:
            if self.arena.coords_have_class((x, y), SpawnPoint):
                try:
                    player = self._player_queue.pop()
                except (IndexError):
                    break

                p_no += 1
                player.spawn(p_no, state=self, coords=(x, y))
                self._sticky_actions[player] = None

    def tick(self, count=1):
        """Step to the next game state: this is an example and is used for testing"""
        for _ in xrange(count):
            self._flames_process()
            self._actions_process()
            self._bombs_process()

    def action_add(self, player, action):
        """Add player actions to a queue for processing"""
        self._action_queue.appendleft((player, action))

    def _actions_process(self):
        """Process queued actions or fall back to sticky actions"""
        unexecuted = deque()
        had_turn = []
        while self._action_queue:
            player, action = self._action_queue.pop()
            if player in had_turn:
                unexecuted.appendleft((player, action))
            else:
#.........这里部分代码省略.........
开发者ID:ahri,项目名称:bombastic,代码行数:103,代码来源:bomber.py


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