Example #1
0
def test_up():
    mapping = {"right": "up", "left": "up", "up": "up", "down": "down"}
    for key in DIRECTIONS:
        snake = Snake()
        snake.direction = key
        snake.up()
        assert snake.direction == mapping[key]
Example #2
0
session_high_score = 0

# -------- Main Program Loop -----------
while not done:
    # --- Main event loop
    for event in pygame.event.get():  # User did something
        if event.type == pygame.QUIT:  # If user clicked close
            done = True  # Flag that we are done so we exit this loop
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT and not snake.turned:
                snake.left()
            elif event.key == pygame.K_RIGHT and not snake.turned:
                snake.right()
            elif event.key == pygame.K_UP and not snake.turned:
                snake.up()
            elif event.key == pygame.K_DOWN and not snake.turned:
                snake.down()
            elif event.key == pygame.K_q:
                """Restart Game"""
                del snake
                snake = Snake()
                HUD.reset_score()
                spider.reset()

    screen.fill(WHITE)
    # --- Game logic
    if snake.alive:
        snake.simulate()
        spider.simulate()
        if snake.head_location == food.location: