def drawBoard(board, message): DISPLAYSURF.fill(BGCOLOR) if message: textSurf, textRect = makeText(message, MESSAGECOLOR, BGCOLOR, 5, 5) DISPLAYSURF.blit(textSurf, textRect) for tilex in range(len(board)): for tiley in range(len(board)): if board[tilex][tiley]: drawTile(tilex, tiley, board[tilex][tiley])
This function handles drawing the entire board and all of its tiles to the
DISPLAYSURF display Surface object. The
fill() method on line 2  completely paints over anything that used to be drawn on the display Surface object before so that we start from scratch.
Line 3  to 5  handles drawing the message at the top of the window. We use this for the "Generating new puzzle..." and other text we want to display at the top of the window. Remember that
if statement conditions consider the blank string to be a
False value, so if message is set to '' then the condition is
False and lines 4  and 5  are skipped.
for loops are used to draw each tile to the display Surface object by calling the