Ejemplo n.º 1
0
def main():
    global win
    win = GraphWin("Practica 1 - Robot", tablero.cols * tablero.cell_size,
                   tablero.rows * tablero.cell_size + 50)
    win.setBackground(color_rgb(192, 192, 192))
    tablero.draw(win)
    butStart.draw(win)
    butWalls.draw(win)
    butRobot.draw(win)
    butClear.draw(win)

    win.bind("<Button-1>", mousepressHandler)
    win.bind("<B1-Motion>", mousedragHandler)

    while True:
        try:
            _ = win.getKey()
        except:
            break
Ejemplo n.º 2
0
def main(
    title='Tiles',
    padding=10,
    density=0.5,
    size=5,
    most=10,
    dimensions={
        'x': 120,  # Pixels left to grid
        'y': 10,  # Pixels down to grid
        'width': 45,  # Width of tile
        'height': 45,  # Height of tile
    }):

    # These are used to construct the board
    x = dimensions['x']
    y = dimensions['y']

    #
    width = padding + x + most * dimensions['width']
    height = padding + y + most * dimensions['height']

    # The window is made just big enough to fit all components at max size
    win = GraphWin(title, width, height)

    # The squares for the game
    grid = Grid(dimensions, size).fill(density)

    # Labels which show the score and state of the game
    labels = {
        'score': Text(Point(x / 2, 140), '0'),
        'state': Text(Point(x / 2, 160), 'Hey There')
    }

    inputs = {
        'density': Input('Density', 0.5, Point(0.7 * x, 180), 4, 0, 1),

        # Minimum is 3, because less and the game is stupid
        'size': Input('Size', 5, Point(0.7 * x, 200), 4, 3, most)
    }

    # The best, reset and exit buttons
    buttons = [
        Button('Best', 'yellow', {
            'x': [padding, x - padding],
            'y': [10, 30]
        }, best(grid, labels)),
        Button('Reset', 'green', {
            'x': [padding, x - padding],
            'y': [40, 60]
        }, reset(win, grid, labels, inputs, dimensions)),
        Button('Exit', 'red', {
            'x': [padding, x - padding],
            'y': [70, 90]
        }, exit)
    ]

    # Bind mouse event handler to window
    win.bind("<Button-1>", click(win, grid, labels, buttons))

    # Bind keyboard press event handler to window
    # This is so the player can move using the directional keys
    win.bind("<Key>", key(move(grid, labels)))

    # Don't quit on me!
    draw(win, grid, labels, inputs, buttons).mainloop()