Highlighting allowed moves

In the on_square_clicked method, we called the draw_board method to take care of the redrawing or changing of the chess pieces' coordinates. The current draw_board method is not equipped to handle this because we only designed it in the first iteration to provide us with a blank chessboard.

First, let's add a HIGHLIGHT_COLOR constant to the configurations.py file, as follows:

HIGHLIGHT_COLOR = "#2EF70D"

Then, modify the draw_board method to handle this, as follows (see 4.06view.py):

def draw_board(self):
current_color = BOARD_COLOR_2
for row in range(NUMBER_OF_ROWS):
current_color = self.get_alternate_color(current_color)
for col in range(NUMBER_OF_COLUMNS):
x1, y1 = self.get_x_y_coordinate(row, col)
x2, y2 = x1 + DIMENSION_OF_EACH_SQUARE, y1 +
DIMENSION_OF_EACH_SQUARE
if(self.all_squares_to_be_highlighted and (row, col) in
self.all_squares_to_be_highlighted):
self.canvas.create_rectangle(x1, y1, x2, y2,
fill=HIGHLIGHT_COLOR)
else:
self.canvas.create_rectangle(x1, y1, x2, y2, fill=current_color)
current_color = self.get_alternate_color(current_color)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.47.166