Ejemplo n.º 1
0
from guizero import App, Waffle
import random


#Action where a pixel on waffle is clicked
def clicked(x, y):
    print(x, y)
    if xTarget == x and yTarget == y:
        print("Hit")


def pickPixel():
    global xTarget, yTarget
    xTarget = random.randint(0, 19)
    yTarget = random.randint(0, 19)
    myWaffle.set_pixel(xTarget, yTarget, "red")
    print("Target is ", xTarget, yTarget)


#Make a window
window1 = App(title="Waffle", width=600, height=800)

#Make a waffle and set properties
myWaffle = Waffle(window1, 20, 20, 20, 3, "white", command=clicked)

#Carry out action after 3 seconds
myWaffle.after(3000, pickPixel)

#display the window
window1.display()
            board[x, y].dotty = False
            board.set_pixel(x, y, "white")
            board.enable()
            puntuaje = 0
            reset.hide()
            texto.value = f"El puntuaje es {puntuaje}"
    board.after(1000, crear_punto())


#Apps
app = App("Destruir puntos", height=250, width=250)

#Widgets
speed = 200
puntuaje = 0
CAJA_TAMAÑO = 5
board = Waffle(app,
               width=CAJA_TAMAÑO,
               height=CAJA_TAMAÑO,
               command=destruir_punto)
board.after(speed, crear_punto)
texto = Text(app, text="El puntuaje es 0")
texto_puntos = Text(app, visible=False)
reset = PushButton(app,
                   text="Reiniciar",
                   visible=False,
                   command=reiniciarJuego)

#display

app.display()
Ejemplo n.º 3
0

def add_dot():
    x, y = randint(0, GRID_SIZE - 1), randint(0, GRID_SIZE - 1)
    while board[x, y].dotty == True:
        x, y = randint(0, GRID_SIZE - 1), randint(0, GRID_SIZE - 1)
    board[x, y].dotty = True
    board.set_pixel(x, y, "red")
    board.after(1000, add_dot)


def destroy_dot(x, y):
    global score
    if board[x, y].dotty == True:
        board[x, y].dotty = False
        board.set_pixel(x, y, "white")
        score += 1
        score_display.value = "Your score is " + str(score)


# App -------------------

app = App("Destroy the dots")

instructions = Text(app, text="Click the dots to destroy them")
board = Waffle(app, width=GRID_SIZE, height=GRID_SIZE, command=destroy_dot)
board.after(1000, add_dot)
score_display = Text(app, text="Your score is " + str(score))

app.display()
Ejemplo n.º 4
0
# Reset the board
def reset():
    global score
    for i in range(board.width):
        for j in range(board.height):
            board[i, j].dotty = False
            board[i, j].color = "white"
    # Restart the game
    score = 0
    score_text.value = "Score: 0"
    board.after(speed, light)
    reset_button.disable()


# Keep track of the pixels
lit = 0
speed = 1000
score = 0

# Create the GUI
app = App()
instructions = Text(app, "Click the dots to destroy them")
board = Waffle(app, width=5, height=5, command=turn_off)
message = Text(app)
score_text = Text(app, text="Score: 0")
reset_button = PushButton(app, reset, text="New game")
reset_button.disable()
# Light a new pixel after a given interval
board.after(speed, light)
app.display()