Exemple #1
0
    def set_marker(self, tile, row, col, direction):
        '''
        Method Description
        '''
        self.reset_marker()
        if self.board.can_place_tile(tile, row, col, direction):

            self.marker[row][col] = tile.get_block(0)
            self.b_marker[row][col] = True

            ad_row, ad_col = DIRECTION.adjust_row_col_by_direction(
                row, col, direction)

            self.marker[ad_row][ad_col] = tile.get_block(1)
            self.b_marker[ad_row][ad_col] = True
        else:
            if row >= 0 and row < self.row_count and col >= 0 and col < self.col_count:
                self.marker[row][col] = tile.get_block(0)
                self.b_marker[row][col] = False

            ad_row, ad_col = DIRECTION.adjust_row_col_by_direction(
                row, col, direction)

            if ad_row >= 0 and ad_row < self.row_count and ad_col >= 0 and ad_col < self.col_count:
                self.marker[ad_row][ad_col] = tile.get_block(1)
                self.b_marker[ad_row][ad_col] = False
 def action_rotate(self):
     '''
     action to rotate
     '''
     if self.tile:
         self.direction = DIRECTION.rotate(self.direction)
         self.board_drawer.set_marker(self.tile, self.row, self.col,
                                      self.direction)
     return False, None
    def is_marked(self, row, col):
        '''
        Implemented BoardInterface is_marked
        returns true if the position is marked
        '''
        if self.row == row and self.col == col:
            return True

        adj_row, adj_col = DIRECTION.adjust_row_col_by_direction(self.row, self.col, self.direction)
        if adj_row == row and adj_col == col:
            return True

        return False
    def __add_tile(self, tile, row, col, direction):
        '''
        Adds Tile to [row][col]+direction
        '''
        self.tiles[row][col] = (tile, direction)

        first_block = tile.get_block(0)
        self.__add_block(first_block, row, col)

        second_block = tile.get_block(1)
        ad_row, ad_col = DIRECTION.adjust_row_col_by_direction(
            row, col, direction)
        self.__add_block(second_block, ad_row, ad_col)
    def rotate(self, count=1):
        '''
        Implemented PieceUpdateHelper rotate
        rotate selected tile by 90 * count degrees
        '''
        if count < 0:
            return False
        # ignore count more then 4 (which is equal to 360 rotation)
        count %= 4

        direction = self.direction
        for _ in range(count):
            direction = DIRECTION.rotate(self.direction)

        return self.__change_tile_position(self.row, self.col, direction)
    def get_block_color(self, row, col):
        '''
        Implemented BoardInterface get_block_color
        returns color of the block located on [row,col]
        '''
        color = self.board.get_block_color(row, col)

        if self.tile:
            # is current [row,col]
            if self.row == row and self.col == col:
                color = self.tile.get_block(0).get_mixed_color(color)

            # is current [row,col,direction]
            row2, col2 = DIRECTION.adjust_row_col_by_direction(self.row, self.col, self.direction)
            if row2 == row and col2 == col:
                color = self.tile.get_block(1).get_mixed_color(color)

        return color
    def get_block_overlap_count(self, row, col):
        '''
        Implemented BoardInterface get_block_overlap_count
        returns overlapped block counts located on [row,col]
        '''
        count = self.board.get_block_overlap_count(row, col)

        if self.tile:
            # is current [row,col]
            if self.row == row and self.col == col:
                count += 1

            # is current [row,col,direction]
            row2, col2 = DIRECTION.adjust_row_col_by_direction(self.row, self.col, self.direction)
            if row2 == row and col2 == col:
                count += 1

        return count
    def __get_adjacent_block_color(self,
                                   row,
                                   col,
                                   direction=DIRECTION.NODIRECTION):
        '''
        returns a list containing adjacent block colors
        '''
        adjacent_colors = list()

        if direction != DIRECTION.NODIRECTION:
            ad_row, ad_col = DIRECTION.adjust_row_col_by_direction(
                row, col, direction)
            success = self.check_row_col_boundary(ad_row, ad_col)
            if success:
                row = ad_row
                col = ad_col
            else:
                return adjacent_colors

        # GET UP BLOCK
        if row > 0:
            color = self.blocks[row - 1][col].get_color()
            adjacent_colors.append(color)

        # GET DOWN BLOCK
        if row < self.row_count - 1:
            color = self.blocks[row + 1][col].get_color()
            adjacent_colors.append(color)

        # GET LEFT BLOCK
        if col > 0:
            color = self.blocks[row][col - 1].get_color()
            adjacent_colors.append(color)

        # GET RIGHT BLOCK
        if col < self.col_count - 1:
            color = self.blocks[row][col + 1].get_color()
            adjacent_colors.append(color)

        return adjacent_colors