Ejemplo n.º 1
0
def test_set_random_angle():
    ball = Ball(300, 400)
    speed = ball.speed[0]
    random.seed(0)
    ball.set_random_angle()
    assert ball.speed[0] == -speed
    assert ball.speed[1] == (10 - speed)
Ejemplo n.º 2
0
    def __init__(self, ball=Ball(X_MIDDLE_SCREEN, Y_MIDDLE_SCREEN)):

        pygame.init()  # pylint: disable=E1101
        self.font = pygame.font.SysFont("monospace", 35)
        self.npc_font = pygame.font.SysFont('Impact', 30)
        self.running = True
        self.clock = pygame.time.Clock()
        self.screen = pygame.display.set_mode(
            (Game.SCREEN_WIDTH, Game.SCREEN_HEIGHT))
        self.left_bat = Bat(Game.SCREEN_HEIGHT, Game.BAT_WIDTH,
                            Game.BAT_HEIGHT, 0, Game.Y_MIDDLE_SCREEN)
        self.left_player = Player(pygame.K_w, pygame.K_s)  # pylint: disable=no-member
        self.right_bat = Bat(
            Game.SCREEN_HEIGHT,  # pylint: disable=no-member
            Game.BAT_WIDTH,
            Game.BAT_HEIGHT,
            Game.RIGHT_BAT_X_POSITION,
            Game.Y_MIDDLE_SCREEN)
        self.right_player = Player(pygame.K_UP, pygame.K_DOWN)  # pylint: disable=no-member
        self.npc_controller = Player(pygame.K_d, pygame.K_f)
        self.ball = ball
        self.ball.rect.y = Game.Y_MIDDLE_SCREEN
        self.ball.rect.x = Game.X_MIDDLE_SCREEN
        self.background = pygame.Surface(self.screen.get_size())  # pylint: disable=too-many-function-args
        self.games = 1
        self.epsilon = 1
        self.old_score = {"p1": 0, "p2": 0}
        self.score = {"p1": 0, "p2": 0}
        self.rect = self.rect = self.screen.get_rect()
        self.npc_on = False
        self.robotron3000 = Ai(self)
Ejemplo n.º 3
0
def test_reset_ball():
    ball = Ball(300, 400)
    ball.rect.x = 0
    ball.rect.y = 0
    ball.set_ball_speed(100, 100)
    random.seed(0)
    ball.reset_ball()
    assert ball.rect.x == 300
    assert ball.rect.y == 400
    assert ball.speed == (10, 0)
Ejemplo n.º 4
0
def test_angle_limiter():
    ball = Ball(300, 400)
    ball.speed = (10, 12)
    ball.angle_limiter(2)
    assert ball.speed[0] == 2
Ejemplo n.º 5
0
def test_update_blocks_top_of_screen():
    ball = Ball(300, 400)
    ball.rect.top = -1
    score = {"p1": 0, "p2": 0}
    ball.update(score)
    assert ball.rect.top == 0
Ejemplo n.º 6
0
def test_set_ball_speed():
    ball = Ball(300, 400)
    ball.set_ball_speed(100, 100)
    assert ball.speed == (100, 100)
Ejemplo n.º 7
0
def test_stop_ball():
    ball = Ball(300, 400)
    ball.stop_ball()
    assert ball.speed == (0, 0)
Ejemplo n.º 8
0
def test_reverse_vertical_direction():
    ball = Ball(300, 400)
    speed = ball.speed[1]
    ball.reverse_vertical_direction()
    assert ball.speed[1] == -speed
Ejemplo n.º 9
0
def test_update_blocks_bottom_of_screen():
    ball = Ball(300, 400)
    ball.rect.bottom = 601
    score = {"p1": 0, "p2": 0}
    ball.update(score)
    assert ball.rect.bottom == 600