Пример #1
0
    def __init__(self):
        """Game class constructor"""
        self.running = True
        self.paused = False
        self.score = 0
        self.game_speed = 10
        self.max_speed = 500
        self.min_speed = 10
        self.snake = snake.Snake()
        self.food = food.Food()
        self.moves = 0

        self.maze = ai.Maze()

        self.snake.head_color = gc.COLOR_ORANGE
        self.snake.body_color = gc.COLOR_YELLOW
        self.food.color = gc.COLOR_PINK

        self.tile1_color = gc.COLOR_DARK_BLUE
        self.tile2_color = gc.COLOR_DARKER_BLUE
        self.score_text_color = gc.COLOR_BLACK
        self.pause_text_color = gc.COLOR_RED

        self.clock = pygame.time.Clock()
        self.screen = pygame.display.set_mode(
            (gc.SCREEN_WIDTH, gc.SCREEN_HEIGHT), 0, 32)
        self.surface = pygame.Surface(self.screen.get_size())
        self.surface = self.surface.convert()

        self.font = pygame.font.SysFont("monospace", 20)
Пример #2
0
def test_snake_move():
    t_snake = snake.Snake()
    t_snake.direction = gc.RIGHT

    current_pos = t_snake.get_head()
    x, y = t_snake.direction
    next_pos = ((current_pos[0] + (x * gc.SQUARE_SIZE)), (current_pos[1] + (y * gc.SQUARE_SIZE)))

    t_snake.move()

    assert t_snake.get_head() == next_pos
Пример #3
0
def test_snake_turn():
    # Turn change test
    t_snake = snake.Snake()
    t_snake.turn(gc.UP)
    assert t_snake.direction == gc.UP
    # Cannot turn back into itself
    t_snake.length = 2
    t_snake.move()
    t_snake.turn(gc.DOWN)
    t_snake.move()
    assert t_snake.direction == gc.UP
Пример #4
0
def test_snake_move_in_random_directions():
    t_snake = snake.Snake()
    moves = random.randint(50, 500)
    for i in range(moves):
        next_dir = random.choice([gc.UP, gc.DOWN, gc.LEFT, gc.RIGHT])
        t_snake.turn(next_dir)
        t_snake.move()
        for pos in t_snake.positions:
            assert pos[0] >= 0
            assert pos[0] <= gc.SCREEN_WIDTH
            assert pos[1] >= 0
            assert pos[1] <= gc.SCREEN_HEIGHT
Пример #5
0
def test_snake_handle_input():
    t_snake = snake.Snake()
    test_event = pygame.event.Event(pygame.locals.KEYDOWN)
    test_event.key = pygame.K_w
    t_snake.handle_input(test_event)
    assert t_snake.direction == gc.UP
    test_event.key = pygame.K_s
    t_snake.handle_input(test_event)
    assert t_snake.direction == gc.DOWN
    test_event.key = pygame.K_a
    t_snake.handle_input(test_event)
    assert t_snake.direction == gc.LEFT
    test_event.key = pygame.K_d
    t_snake.handle_input(test_event)
    assert t_snake.direction == gc.RIGHT
Пример #6
0
def test_snake_reset():
    t_snake = snake.Snake()
    default_pos = t_snake.get_head()
    # move the snake somewhere else
    t_snake.turn(gc.UP)
    t_snake.move()
    t_snake.length += 1
    t_snake.move()
    t_snake.move()
    assert t_snake.get_head() != default_pos

    t_snake.reset()

    assert t_snake.get_head() == default_pos
    assert t_snake.length == 1
Пример #7
0
    def __init__(self):
        """Game class constructor"""
        self.running = True
        self.paused = False
        self.score = 0
        self.high_score = 0
        self.game_speed = 6
        self.snake = snake.Snake()
        self.food = food.Food()
        self.moves = 0

        self.tile1_color = gc.COLOR_LIGHT_BLUE
        self.tile2_color = gc.COLOR_BLUE
        self.score_text_color = gc.COLOR_BLACK
        self.pause_text_color = gc.COLOR_RED

        self.clock = pygame.time.Clock()
        self.screen = pygame.display.set_mode(
            (gc.SCREEN_WIDTH, gc.SCREEN_HEIGHT), 0, 32)
        self.surface = pygame.Surface(self.screen.get_size())
        self.surface = self.surface.convert()

        self.font = pygame.font.SysFont("monospace", 25)
        self.pause_font = pygame.font.SysFont("monospace", 40, True)
Пример #8
0
def test_snake_get_tail():
    t_snake = snake.Snake()
    assert t_snake.get_tail() == t_snake.positions[-1]
Пример #9
0
def test_snake_get_head():
    t_snake = snake.Snake()
    assert t_snake.get_head() == t_snake.positions[0]
Пример #10
0
def test_snake_init():
    expected_direction = (0, 0)
    t_snake = snake.Snake()
    assert expected_direction == t_snake.direction