graphbox5Rect.center = (boundarySpacing - 5, boundarySpacing-10) scaleRect.center = (size[0] / 2, boundarySpacing - 10) graphbox6Rect.center = (boundarySpacing + ((size[0] - 2 * boundarySpacing) / 4), size[1] - boundarySpacing + 10) graphbox7Rect.center = (boundarySpacing + ((size[0] - 2 * boundarySpacing) * 3 / 4), size[1] - boundarySpacing + 10) graphbox8Rect.center = (boundarySpacing - 5, (size[1] - boundarySpacing)* 3/4) graphbox9Rect.center = (boundarySpacing - 5, (size[1] - boundarySpacing) / 4) for box in input_boxes: box.handle_event(event) # User has clicked mouse button if event.type == pygame.MOUSEBUTTONUP: pos = pygame.mouse.get_pos() print(pos) if event.button == 1: #Left click # Check if user clicked on one of the buttons if resetButton.clicked(pos): walls = [] addBoundaries() for box in input_boxes: box.update() elif playButton.clicked(pos): # Change status of play button if play: playButton.color = GREEN playButton.text = 'Play' else: playButton.color = YELLOW playButton.text = 'Stop' drawing = False
# setup button BUTTON_START_X = 475 BUTTON_START_Y = 120 LARGE_WIDTH = 129 LARGE_HEIGHT = 50 LARGE_FONT = 28 SMALL_WIDTH = 40 SMALL_HEIGHT = 25 SMALL_FONT = 18 GAP = 8 newGameButton = Button((BUTTON_START_X, BUTTON_START_Y), LARGE_WIDTH, LARGE_HEIGHT, LARGE_FONT, "New Game", GRID_WIDTH, win) easyButton = Button((BUTTON_START_X, BUTTON_START_Y + LARGE_HEIGHT), SMALL_WIDTH, SMALL_HEIGHT, SMALL_FONT, "Easy", GRID_WIDTH, win) easyButton.clicked = True mediumButton = Button((BUTTON_START_X + SMALL_WIDTH, BUTTON_START_Y + LARGE_HEIGHT), SMALL_WIDTH + 9, SMALL_HEIGHT, SMALL_FONT, "Medium", GRID_WIDTH, win) hardButton = Button((BUTTON_START_X + 2*SMALL_WIDTH + 9, BUTTON_START_Y + LARGE_HEIGHT), SMALL_WIDTH, SMALL_HEIGHT, SMALL_FONT, "Hard", GRID_WIDTH, win) checkBoardButton = Button((BUTTON_START_X, BUTTON_START_Y + LARGE_HEIGHT + SMALL_HEIGHT + GAP), LARGE_WIDTH, LARGE_HEIGHT, LARGE_FONT, "Check Board", GRID_WIDTH, win) checkMoveButton = Button((BUTTON_START_X, BUTTON_START_Y + 2*LARGE_HEIGHT + SMALL_HEIGHT + 2*GAP), LARGE_WIDTH, LARGE_HEIGHT, LARGE_FONT, "Check Move", GRID_WIDTH, win) solveButton = Button((BUTTON_START_X, BUTTON_START_Y + 3*LARGE_HEIGHT + SMALL_HEIGHT + 3*GAP), LARGE_WIDTH, LARGE_HEIGHT, LARGE_FONT, "Solve", GRID_WIDTH, win) clearButton = Button((BUTTON_START_X, BUTTON_START_Y + 4*LARGE_HEIGHT + SMALL_HEIGHT + 4*GAP), LARGE_WIDTH, LARGE_HEIGHT, LARGE_FONT, "Clear", GRID_WIDTH, win) # setup clock clock = Clock((BUTTON_START_X, BUTTON_START_Y - 75), time.time(), win, WIN_COLOUR,