예제 #1
0
                pos = pygame.mouse.get_pos()
                clicked_cells = []
                for row in bfs.cells:
                    for c in row:
                        if c.rect.collidepoint(pos):
                            clicked_cells.append(c)
                for c in clicked_cells:
                    c.toggle_wall()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE:
                RUNNING = True

    screen.fill((255, 255, 255))

    if RUNNING:
        path = bfs.step()
        if path is not None:
            break

    bfs.draw(screen)
    pygame.display.flip()
    clock.tick(60)

for cell in path:
    cell.is_path = True

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()