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


Python Tile.set_color方法代码示例

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


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

示例1: get_puzzle_pieces

# 需要导入模块: from tile import Tile [as 别名]
# 或者: from tile.Tile import set_color [as 别名]
    def get_puzzle_pieces(self, content):
        all_tiles = []
        all_indexes = []
        all_pieces = []

        # find position and color of each tile and store it
        tile_position_y = 0
        color1 = ''
        color2 = ''
        for line in content:
            tile_position_x = 0
            for letter in line:
                if letter != ' ':
                    new_position = [tile_position_x, tile_position_y]
                    new_tile = Tile(new_position)
                    all_indexes.append(new_position)
                    if letter == color2:
                        new_tile.set_color(1)
                    elif color1 == '':
                        color1 = letter
                    elif color2 == '' and letter != color1:
                        color2 = letter
                        new_tile.set_color(1)
                    all_tiles.append(new_tile)

                tile_position_x = tile_position_x + 1
            tile_position_y = tile_position_y + 1

        # searches through list of tiles to find pieces
        piece_to_tile = {}
        for tile in all_tiles:
            position = tile.get_position()
            str_position = str(position)
            check_position_up = [position[0], position[1] - 1]
            check_position_left = [position[0] - 1, position[1]]
            check_position_up_right = [position[0] + 1, position[1] - 1]

            if check_position_up in all_indexes or check_position_left in all_indexes or check_position_up_right in all_indexes:
                for piece in all_pieces:
                    blocks = piece.get_positions()
                    if check_position_up in blocks or check_position_left in blocks or check_position_up_right in blocks:
                        piece.add_block(tile)
                        if str_position in piece_to_tile:
                            # combine current piece and piece with same tile
                            # remove both from all_pieces and add new_piece
                            conflict_piece = piece_to_tile[str_position]
                            new_piece = combine_pieces(piece, conflict_piece)
                            all_pieces.remove(piece)
                            all_pieces.remove(conflict_piece)
                            all_pieces.append(new_piece)

                            piece_to_tile[str_position] = new_piece
                        else:
                            piece_to_tile[str_position] = piece
            else:
                piece = Piece([tile])
                all_pieces.append(piece)
                piece_to_tile[str_position] = piece

        # for key in all_pieces:
        #     print key.get_size()
        all_pieces = zero_pieces(all_pieces)

        # searches through list of pieces to find the board (largest piece)
        largest_piece_index = 0
        largest_size = 0
        piece_index = 0
        for piece in all_pieces:
            if piece.get_size() > largest_size:
                largest_piece_index = piece_index
                largest_size = piece.get_size()
            piece_index = piece_index + 1

        board = all_pieces[largest_piece_index]
        board.set_board(True)
        all_pieces.remove(board)

        # import pdb; pdb.set_trace()

        return [all_pieces, board]
开发者ID:leb2dg,项目名称:ProblemSolver,代码行数:82,代码来源:gui.py


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