创建一个不需要用鼠标移动更新的网格 - Pygame

时间:2017-11-23 20:11:27

标签: python python-3.x pygame

很抱歉,如果这是非常具体的,但我无法想象我的生活。我创建了一个游戏LightsOut的版本,其中一个网格代表了棋盘。正如你所看到的,我有两次绘制网格......?它随着鼠标移动而闪烁,我正试图找到一种方法来阻止它。有人有想法吗?谢谢。这是有问题的代码:

size = 5

grid = []
for x in range(5):
    column = []
    for y in range(5):
        column.append(white)
    grid.append(column)

#####################################

drawing = True

while drawing:

    # MAKES THE GRID #

    for a in range(size + 1):
        for b in range(size + 1):
            r = pygame.Rect(a * 100, b * 100, 100, 100)
            border = 0
            if grid[a][b] == (0, 0, 0):
                border = 5
            pygame.draw.rect(w, grid[a][b], r, border)

    for event in pygame.event.get():

        if event.type == pygame.MOUSEBUTTONDOWN:

            # INVERTS BOXES #

            (x, y) = pygame.mouse.get_pos()
            grid_x = int(x / 100)
            grid_y = int(y / 100)
            invert(grid, (grid_x, grid_y))

            pygame.display.flip()

    ############

        for grid_x in range(size + 1):
            for grid_y in range(size + 1):
                rect = pygame.Rect(grid_x * 100, grid_y * 100, 100, 100)
                pygame.draw.rect(w, (0, 0, 0), rect, 5)
                pygame.display.flip()

0 个答案:

没有答案