Skip to main content
Engineering LibreTexts

5.24: Drawing the Board

  • Page ID
    14515
  • 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[0])):
                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 [234] completely paints over anything that used to be drawn on the display Surface object before so that we start from scratch.

    Line 3 [235] to 5 [237] 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 [236] and 5 [237] are skipped.

    Next, nested for loops are used to draw each tile to the display Surface object by calling the drawTile() function.

    • Was this article helpful?