import pygame

import pygame

WIDTH = 480  # Ширина игрового окна
HEIGHT = 600  # Высота
FPS = 60  # Кадры в секунду

WHITE = (255, 255, 255)  # Белый
BLACK = (0, 0, 0)  # Черный
RED = (255, 0, 0)  # Красный
GREEN = (0, 255, 0)  # Зеленый
BLUE = (0, 0, 255)  # Синий
VIOLET = (238, 130, 238)  # Цвет на выбор
OLIVE = (128, 128, 0) #оливье
STEELBLUE = (70, 130, 180) #блевония

pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("чичигага")
clock = pygame.time.Clock

snake_block = 10
snake_speed = 15

class Snake(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.Surface((snake_block,snake_block))
        self.image.fill(STEELBLUE)
        self.image = self.image.get_rect()
        self.rect.x = WIDTH/2
        self.rect.y = HEIGHT/2
        self.dx = 0
        self.dy = 0
        self.body = []
        self.lenght = 1
        self.score = 0
    def update(self):
        self.rect.y += self.dy
        self.rect.x += self.dx

        self.body.append[self.rect.x, self.rect.y]
        if len(self.body)>self.lenght:
            del self.body[0]

        for segment in self.body[:-1]:
            if segment[0] == self.rect.x and segment[1] == self.rect.y:
                return False
        return True
    def draw_body(self,surfase):
        for segment in self.body[:-1]:
            pygame.draw.rect(surfase, BLACK, segment[0], segment[1], snake_block, snake_block)

    def grow(self):
        self.lenght += 1  #self.lenght = self.lenght + 1
        self.score += 1


class Food(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.Surface((snake_block, snake_block))
        self.image.fill(OLIVE)
        self.image = self.image.get_rect()
        self.respawn()



    def respawn(self):
        self.rect.x = random.randrange(0,480-snake_block, snake_block)
        self.rect.y = random.randrange(0,600-snake_block,snake_block)


#clock = pygame.time.Clock()
all_sprites = pygame.sprite.Group()
player = Player()
all_sprites.add(player)


class Player(pygame.sprite.Sprite):

Running = True
while running:

    clock.tick(FPS)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT and player.dx == 0:
                player.dx = -snake_block
                player.dy = 0
            elif event.key == pygame.K_RIGHT and player.dx == 0:
                player.dx = snake_block
                player.dy = 0
            elif event.key == pygame.K_DOWN and player.dx == 0:
                player.dx = -snake_block
                player.dy = 0
            elif event.key == pygame.K_UP and player.dx == 0:
                player.dx = snake_block
                player.dy = 0

    if player.update():
        running = False

    if (player.redt.x < 0 or player.rect.x > WIDTH or ):
        running = False


    if pygame.sprite.spritecollide(player, foods, True)
        player.grow()
        new_food = Food()
        all_sprites.add(new_food)
        foods.add(new_food)




    screen.fill(WHITE)
    all_sprites.draw(screen)
    pygame.display.flip()


pygame.quit()
