Загрузка данных


BG_COLOR = "black"
TEXT_COLOR = "white"



wn = turtle.Screen()
wn.setup(WIDTH, HEIGHT)
wn.bgcolor(BG_COLOR)

try:
    wn.title("Змейка")
except:
    pass  
wn.tracer(0)                      
wn.listen()                       


def check_food_collision(head):
    
    global score
    if head.distance(food) < CELL_SIZE // 2:
        score += 1
        update_score_display()
        return True
    return False


def update_score_display():
    
    pen.clear()
    pen.write(f"Счёт: {score}", align="left", font=("Comic Sans MS", 14, "normal"))



start_pen = None  

def start_screen()
    
    global start_pen
    start_pen = turtle.Turtle()
    start_pen.hideturtle()
    start_pen.color(TEXT_COLOR)
    start_pen.penup()
    
    
    start_pen.goto(0, 100)
    start_pen.write("ЗМЕЙКА", align="center", font=("Comic Sans MS", 36, "bold"))
    

    start_pen.goto(0, -120)
    start_pen.write("Нажмите ПРОБЕЛ, чтобы начать", align="center", font=("Comic Sans MS", 18, "bold"))
    
    wn.update()
    
    
    wn.onkey(start_game, "space")
    wn.onkey(None, "Up")      
    wn.onkey(None, "Down")
    wn.onkey(None, "Left")
    wn.onkey(None, "Right")

def start_screen_clear():
    
    global start_pen
    if start_pen:
        start_pen.clear()
        start_pen.hideturtle()



def game_over():
    
    global game_running, start_pen
    game_running = False
    
    
    for seg in snake_segments:
        seg.hideturtle()
        seg.clear()
    if food:
        food.hideturtle()
        food.clear()
    
   
    start_pen.goto(0, 100)
    start_pen.write("Game over", align="center", font=("Comic Sans MS", 36, "bold"))
    start_pen.goto(0, 30)
    start_pen.write(f"Ваш счёт: {score}", align="center", font=("Comic Sans MS", 24, "normal"))
    start_pen.goto(0, -40)
    start_pen.write("Нажмите ПРОБЕЛ, чтобы начать заново", align="center", font=("Comic Sans MS", 18, "bold"))
    wn.update()
    
    
    wn.onkey(start_game, "space")
    wn.onkey(None, "Up")
    wn.onkey(None, "Down")
    wn.onkey(None, "Left")
    wn.onkey(None, "Right")



pen = turtle.Turtle()
pen.hideturtle()
pen.color(TEXT_COLOR)
pen.penup()
pen.goto(-WIDTH//2 + 10, HEIGHT//2 - 30)
pen.write("Счёт: 0", align="left", font=("Comic Sans MS", 14, "normal"))


start_screen()


wn.mainloop()