示例#1
0
    def test_can_move_right_paddle_up(self):
        hit_wall = pygame.mixer.Sound('../sounds/pong_wall.wav')
        hit_paddle = pygame.mixer.Sound('../sounds/pong_wall.wav')
        pong = Pong(hit_wall, hit_paddle)

        pong.move_right_up()
        self.assertEqual(
            pong.rightPaddle.y,
            Config.paddle_right_start_y - pong.rightPaddle.step_size)
示例#2
0
ball = Ball(Config.ball_left_start_x, Config.ball_left_start_y,
            Config.ball_size)
score = Score()
pong = Pong(leftPaddle, rightPaddle, ball, score, hit_wall, hit_paddle,
            Config.color)

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

    keys = pygame.key.get_pressed()
    if keys[pygame.K_q]:
        pong.move_left_up()

    if keys[pygame.K_a]:
        pong.move_left_down()

    if keys[pygame.K_p]:
        pong.move_right_up()

    if keys[pygame.K_l]:
        pong.move_right_down()

    if keys[pygame.K_SPACE]:
        pong.serve()

    pong.move_ball()
    pong.draw(screen)
    pygame.time.delay(10)