def test_can_move_left_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_left_up() self.assertEqual( pong.leftPaddle.y, Config.paddle_left_start_y - pong.leftPaddle.step_size)
def test_can_not_move_paddle_above_upper_limit(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) paddle = Paddle(20, Config.paddle_upper_limit) pong.leftPaddle = paddle pong.move_left_up() self.assertEqual(pong.leftPaddle.y, Config.paddle_upper_limit)
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)