Exemple #1
0
    time.sleep(0.1)
    snake.move()

    # detecting collision with the food
    if snake.head.distance(food) < 15:
        food.refresh()
        snake.extend()
        score.sum_score()

#  detecting collision with wall
    if snake.head.xcor() > 280 or snake.head.xcor() < -300 or snake.head.ycor() > 280 or snake.head.ycor() < -280:
<<<<<<< HEAD
        game_is_on = False
        score.game_over()
=======
        score.reset()
        snake.reset()
>>>>>>> 0530d7b... Initial commit

# detecting collision with tail
    for segment in snake.segments[1:]:
        if snake.head.distance(segment) < 10:
<<<<<<< HEAD
            game_is_on = False
            score.game_over()
=======
            score.reset()
            snake.reset()

>>>>>>> 0530d7b... Initial commit
screen.exitonclick()
Exemple #2
0
screen.onkey(snake.left, "Left")
screen.onkey(snake.right, "Right")

game_is_on = True
while game_is_on:
    screen.update()
    time.sleep(0.1)

    snake.move()
    '''Detect collision with food'''

    if snake.head.distance(food) < 15:
        food.refresh()
        snake.extend()
        scoreboard.increase_score()
    '''Detect collision with wall'''

    if snake.head.xcor() > 280 or snake.head.xcor() < -280 or snake.head.ycor(
    ) > 280 or snake.head.ycor() < -280:
        scoreboard.reset()
        snake.reset()
    '''Detect collision with tail'''

    for segment in snake.segments[1:]:
        if snake.head.distance(segment) < 10:
            scoreboard.reset()
            snake.reset()
'''if head collides with any segment in the tail, trigger game_over'''

screen.exitonclick()