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


Python Tile.exit_img方法代码示例

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


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

示例1: load

# 需要导入模块: from tile import Tile [as 别名]
# 或者: from tile.Tile import exit_img [as 别名]
    def load(self, ZONE_N):
        '''(Zone, str) -> NoneType
        Loads Zone from Zone given in ZONE_N. Assumes success. Format for
        map files:

        min <int_value>
        max <int_value>
        img <index> <img_name>
        ...
        map
        XYZ ...
        ...

        min, max - optional entries to specific inclusive range for randomly
                   generated integers for tile values, which is used if given
                   a ? character
        img      - optional entry or entries to specify images for tiles
                   (images are not required by tiles). <img_name> is added to
                   a list, and <index> corresponds with the index in the list.
        map      - an array of tile entries, which are X,Y,Z,U , separated by spaces.
                   X is the type of tile to be loaded: 0 for default tile, 1
                   for trap, 2 is wall, 3 is key, 4 is lock, 5 is exit. Y is
                   the img index for the primary img to be used, where 0 means
                   no img. Z is the value
                   to be given to the tile, where ? means a random value
                   generated using min, max. U is the secondary img to be used, 0
                   for no img.'''
        TILE_SIZE = get_tile_size()

        # Seed random in case random values are to be generated
        random.seed()

        PATH = _get_zone_path(ZONE_N)
        with open(PATH) as FILE:
            min = None
            max = None
            img_list = [None] # None there for use of 0 for no img

            line = FILE.readline()
            while line:
                data = line.split()
                if data[0] == "min":
                    min = int(data[1])
                elif data[0] == "max":
                    max = int(data[1])
                elif data[0] == "start":
                    coord = (int(data[1]), int(data[2]))
                elif data[0] == "img":
                    img_list.append(data[2])
                elif data[0] == "map":
                    # Map is rest of file
                    line = FILE.readline()
                    for i in range(self.num_tiles_h): # Row number of data
                        data = line.split()
                        for j in range(self.num_tiles_w): # Column number of data
                            tile = data[j].split(",")

                            tile_s = Tile(j * TILE_SIZE, i * TILE_SIZE)
                            img_index = int(tile[1])
                            sec_img_index = int(tile[3])

                            #loads the image of the tile
                            if img_index:
                                tile_s.load_img(img_list[img_index])

                            #gives the tile a value
                            if tile[2] == "?":
                                # Randomize value given by min, max
                                tile_s.value = random.randint(min, max)
                            else:
                                tile_s.value = int(tile[2])

                            # Determine tile type
                            if tile[0] == "0": # Normal
                                pass
                            elif tile[0] == "1": # Trap
                                tile_s.trap = True
                                tile_s.load_trapimg(img_list[sec_img_index])
                            elif tile[0] == "2": # Wall
                                tile_s.wall = True
                                tile_s.wall_img = load_img(img_list[sec_img_index])
                            elif tile[0] == "3": # Key
                                tile_s.key = True
                                tile_s.key_img = load_img(img_list[sec_img_index])
                            elif tile[0] == "4": # Lock
                                tile_s.lock = True
                                tile_s.lock_img = load_img(img_list[sec_img_index])
                            elif tile[0] == "5": # Exit
                                tile_s.exit = True
                                tile_s.exit_img = load_img(img_list[sec_img_index])

                            self.map[j][i] = tile_s

                        line = FILE.readline()

                line = FILE.readline()

        self.player = Player(*coord) # Starting coords
开发者ID:Roolymoo,项目名称:pyweek18,代码行数:100,代码来源:zone.py


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