예제 #1
0
def test_simulate():
    snake = Snake()
    snake.simulate()
    assert type(snake.head_location[0]) is int
    assert type(snake.head_location[1]) is int
    for i, val1 in enumerate(snake.snake_matrix):
        for j, val2 in enumerate(snake.snake_matrix[i]):
            assert type(snake.snake_matrix[i][j]) is int
예제 #2
0
파일: app.py 프로젝트: dariuscm/snake
                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:
            snake.eat()
            food.consumed()
            HUD.add_score(DIFFICULTY)
        if snake.head_location == spider.location:
            HUD.add_score(spider.score())
            snake.eat()
            spider.consumed()

    # --- Drawing
    if snake.alive:
        food.draw(screen)
        snake.draw(screen)
        spider.draw(screen)