예제 #1
0
def test_left():
    mapping = {"right": "right", "left": "left", "up": "left", "down": "left"}
    for key in DIRECTIONS:
        snake = Snake()
        snake.direction = key
        snake.left()
        assert snake.direction == mapping[key]
예제 #2
0
파일: app.py 프로젝트: dariuscm/snake
snake = Snake()
food = Food()
HUD = hud()
spider = Spider(DIFFICULTY)

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