コード例 #1
0
    def place_player_tile(self, inp_x_tile, inp_y_tile, inp_color,
                          board_update=True):
        """Places the tile on the board and updates board_cord list"""
        valid_tile = 0
        add_dist = False
        tile = Tile(inp_x_tile, inp_y_tile, self.CHAR_WIDTH, inp_color)
        tile.draw_tile(self.x_add_disc, self.y_add_disc, add_dist)

        if board_update:
            for j in range(self.NUM_SQUARES):
                for i in range(self.NUM_SQUARES):
                    if(self.board_cord[j][i] == (inp_y_tile, inp_x_tile)):
                        valid_tile = 1
                        self.board_cord[j][i] = None
                        row = j
                        col = i
                        break
                    elif(self.board_cord[j][i] is None):
                        valid_tile = 0
                if(valid_tile == 1):
                    break
            self.list_tiles[row][col] = tile
        else:
            row = (inp_y_tile/self.CELL_WIDTH)-self.ADD1_FACTOR
            col = (inp_x_tile/self.CELL_WIDTH)-self.ADD1_FACTOR
            self.list_tiles[row][col] = tile
コード例 #2
0
    def place_initial_tile(self):
        """Places the first four tiles and update the list_tiles accordingly"""
        self.create_list_tiles()
        add_dist = True
        x_tile = (self.FIRST_TILE)
        y_tile = (self.FIRST_TILE)
        color = self.WHITE
        tile = Tile(x_tile, y_tile, self.CHAR_WIDTH, color)
        self.list_tiles[self.HALF_SQUARES-1][self.HALF_SQUARES-1] = tile
        tile.draw_tile(self.x_add_disc, self.y_add_disc, add_dist)

        x_tile = (self.FIRST_TILE+self.CELL_WIDTH)
        y_tile = (self.FIRST_TILE)
        color = self.BLACK
        tile = Tile(x_tile, y_tile, self.CHAR_WIDTH, color)
        self.list_tiles[self.HALF_SQUARES-1][self.HALF_SQUARES] = tile
        tile.draw_tile(self.x_add_disc, self.y_add_disc, add_dist)

        x_tile = (self.FIRST_TILE)
        y_tile = (self.FIRST_TILE+self.CELL_WIDTH)
        color = self.BLACK
        tile = Tile(x_tile, y_tile, self.CHAR_WIDTH, color)
        self.list_tiles[self.HALF_SQUARES][self.HALF_SQUARES-1] = tile
        tile.draw_tile(self.x_add_disc, self.y_add_disc, add_dist)

        x_tile = (self.FIRST_TILE+self.CELL_WIDTH)
        y_tile = (self.FIRST_TILE+self.CELL_WIDTH)
        color = self.WHITE
        tile = Tile(x_tile, y_tile, self.CHAR_WIDTH, color)
        self.list_tiles[self.HALF_SQUARES][self.HALF_SQUARES] = tile
        tile.draw_tile(self.x_add_disc, self.y_add_disc, add_dist)
コード例 #3
0
    def place_tile(self, color, position):
        '''
        Method place_tile
        Parameters: str (color), tuple (coordinates of square)
        Returns: nothing
        Does: creates tile object of given color at given position; draws
                tile in square on board; adds tile to list of tile objects
                in board's tiles attribute; adds tile color at given coord
                to board's status attribute
        '''
        # Instantiate tile object
        tile = Tile(color, position)

        # Draw tile on the board
        tile.draw_tile()

        # Append tile object to list of tiles
        self.tiles.append(tile)

        # Write tile color in status list at corresponding coordinates
        self.status[position[0]][position[1]] = color