Пример #1
0
def main():
    graphics = BreakoutGraphics(brick_cols=10, brick_rows=10)

    # Add animation loop here!
    lives = NUM_LIVES
    while lives > 0:
        pause(FRAME_RATE)
        vx = graphics.get_vx()
        vy = graphics.get_vy()
        if graphics.switch is True:
            graphics.ball_move(vx, vy)
            graphics.check_hit_object()
            if graphics.ball.y - graphics.ball.height <= 0:
                graphics.set_vy(-vy)
            if graphics.ball.x <= 0 or graphics.ball.x + graphics.ball.width > graphics.window.width:
                graphics.set_vx(-vx)
            if graphics.ball.y > graphics.window.height:
                graphics.reset()
                lives -= 1
            if graphics.brick_counts == 0:
                break
Пример #2
0
def main():
    graphics = BreakoutGraphics()
    graphics.life = NUM_LIVES
    for i in range(NUM_LIVES):
        # How many live does the player have.
        while True:  # switch that control game start after a click.
            if graphics.start1:
                graphics.ball.move(graphics.get_dx(), graphics.get_dy())
                graphics.check_hit_wall()
                graphics.check_hit_object()
                if graphics.ball.y >= graphics.window.height:
                    # ball fall off the bottom.
                    graphics.reset()
                    break
                elif graphics.bricks_num == 0:
                    # clear all the bricks!
                    graphics.window.remove(graphics.ball)
                    break
            pause(FRAME_RATE)
    # Game Over
    gameover = GLabel('GAME OVER!')
    gameover.font = 'Garamond-60'
    gameover.color = 'magenta'
    graphics.window.add(gameover, (graphics.window.width-gameover.width)/2, graphics.window.height/2)