import pygame, random
from pygame.locals import *

UP = 0
RIGHT = 1
DOWN = 2
LEFT = 3

# FUNÇÃO DE CRIAR POSIÇÃO ALEATÓRIA NO GRID (ALINHADO)
def on_grid_random():
    x = random.randint(0,640)
    y = random.randint(0, 640)
    return (x//10 *10, y//10 *10)

# FUNÇÃO DE COLISÃO
def collision (c1,c2):
    return (c1 [0] == c2 [0]) and (c1 [1] == c2 [1])


# CRIAR A TELA INICIAL COM O NOME DO JOGO
pygame.init()
screen = pygame.display.set_mode ((650,650))
pygame.display.set_caption ('Snake')

# DEFINIR O SEGUIMENTO DA COBRA ATRAVÉS DE TUPLAS
snake = [(200,200), (210,200) , (220,200)]
# DEFINIR DIMENSẼS E COR DA COBRA
snake_skin = pygame.Surface((10,10))
snake_skin.fill((255,255,255))
# INDICAR A DIREÇÃO DA COBRA
my_direction = LEFT

# MAÇÃ PARA A COBRA COMER
apple = pygame.Surface((10,10))
apple.fill((255,0,0))
# GERAR UMA POSIÇÃO ALEATÓRIA PARA A MAÇÃ
apple_pos = on_grid_random()
# PARA COBRA SE MOVIMENTAR NUMA VELOCIDADE VISÍVEL
clock = pygame.time.Clock()

while True:
    clock.tick(10)
    # EVENTO PARA FECHAR A TELA DO JOGO
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()


        # A COLISÃO -> AUMENTAR A COBRA E GERAR UMA NOVA POSIÇÃO PARA A MAÇÃ
        if collision(snake [0], apple_pos):
            apple_pos = on_grid_random()
            snake.append((0,0))

        # PARA CONTROLAR A COBRA
        if event.type == KEYDOWN:
            if event.key == K_UP:
                my_direction = UP
            if event.key == K_DOWN:
                my_direction = DOWN
            if event.key == K_LEFT:
                my_direction = LEFT
            if event.key == K_RIGHT:
                my_direction = RIGHT


    # COMANDOS ATRAVÉS DE TUPLAS PARA MOVIMENTAÇÃO DA COBRA
    if my_direction == UP:
        snake[0] = (snake[0][0], snake [0][1] - 10)
    if my_direction == DOWN:
        snake[0] = (snake[0][0], snake[0][1] + 10)
    if my_direction == LEFT:
        snake[0] = (snake[0][0] -10 , snake[0][1])
    if my_direction == RIGHT:
        snake[0] = (snake[0][0] + 10, snake[0][1])

    # PARA MEXER O CORPO DA COBRA
    for i in range (len(snake) -1,0,-1):
        snake [i] = (snake [i-1][0], snake[i-1][1])






    screen.fill ((0,0,0))
    screen.blit (apple,apple_pos)
    for pos in snake:
        screen.blit(snake_skin,pos)

    pygame.display.update()

8ba658dd7dc3bbe3fca2111f9c36d1665bc43f5e
<mask token>


def on_grid_random():
    x = random.randint(0, 640)
    y = random.randint(0, 640)
    return x // 10 * 10, y // 10 * 10


def collision(c1, c2):
    return c1[0] == c2[0] and c1[1] == c2[1]


<mask token>

<mask token>


def on_grid_random():
    x = random.randint(0, 640)
    y = random.randint(0, 640)
    return x // 10 * 10, y // 10 * 10


def collision(c1, c2):
    return c1[0] == c2[0] and c1[1] == c2[1]


pygame.init()
<mask token>
pygame.display.set_caption('Snake')
<mask token>
snake_skin.fill((255, 255, 255))
<mask token>
apple.fill((255, 0, 0))
<mask token>
while True:
    clock.tick(10)
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
        if collision(snake[0], apple_pos):
            apple_pos = on_grid_random()
            snake.append((0, 0))
        if event.type == KEYDOWN:
            if event.key == K_UP:
                my_direction = UP
            if event.key == K_DOWN:
                my_direction = DOWN
            if event.key == K_LEFT:
                my_direction = LEFT
            if event.key == K_RIGHT:
                my_direction = RIGHT
    if my_direction == UP:
        snake[0] = snake[0][0], snake[0][1] - 10
    if my_direction == DOWN:
        snake[0] = snake[0][0], snake[0][1] + 10
    if my_direction == LEFT:
        snake[0] = snake[0][0] - 10, snake[0][1]
    if my_direction == RIGHT:
        snake[0] = snake[0][0] + 10, snake[0][1]
    for i in range(len(snake) - 1, 0, -1):
        snake[i] = snake[i - 1][0], snake[i - 1][1]
    screen.fill((0, 0, 0))
    screen.blit(apple, apple_pos)
    for pos in snake:
        screen.blit(snake_skin, pos)
    pygame.display.update()

<mask token>
UP = 0
RIGHT = 1
DOWN = 2
LEFT = 3


def on_grid_random():
    x = random.randint(0, 640)
    y = random.randint(0, 640)
    return x // 10 * 10, y // 10 * 10


def collision(c1, c2):
    return c1[0] == c2[0] and c1[1] == c2[1]


pygame.init()
screen = pygame.display.set_mode((650, 650))
pygame.display.set_caption('Snake')
snake = [(200, 200), (210, 200), (220, 200)]
snake_skin = pygame.Surface((10, 10))
snake_skin.fill((255, 255, 255))
my_direction = LEFT
apple = pygame.Surface((10, 10))
apple.fill((255, 0, 0))
apple_pos = on_grid_random()
clock = pygame.time.Clock()
while True:
    clock.tick(10)
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
        if collision(snake[0], apple_pos):
            apple_pos = on_grid_random()
            snake.append((0, 0))
        if event.type == KEYDOWN:
            if event.key == K_UP:
                my_direction = UP
            if event.key == K_DOWN:
                my_direction = DOWN
            if event.key == K_LEFT:
                my_direction = LEFT
            if event.key == K_RIGHT:
                my_direction = RIGHT
    if my_direction == UP:
        snake[0] = snake[0][0], snake[0][1] - 10
    if my_direction == DOWN:
        snake[0] = snake[0][0], snake[0][1] + 10
    if my_direction == LEFT:
        snake[0] = snake[0][0] - 10, snake[0][1]
    if my_direction == RIGHT:
        snake[0] = snake[0][0] + 10, snake[0][1]
    for i in range(len(snake) - 1, 0, -1):
        snake[i] = snake[i - 1][0], snake[i - 1][1]
    screen.fill((0, 0, 0))
    screen.blit(apple, apple_pos)
    for pos in snake:
        screen.blit(snake_skin, pos)
    pygame.display.update()

import pygame, random
from pygame.locals import *
UP = 0
RIGHT = 1
DOWN = 2
LEFT = 3


def on_grid_random():
    x = random.randint(0, 640)
    y = random.randint(0, 640)
    return x // 10 * 10, y // 10 * 10


def collision(c1, c2):
    return c1[0] == c2[0] and c1[1] == c2[1]


pygame.init()
screen = pygame.display.set_mode((650, 650))
pygame.display.set_caption('Snake')
snake = [(200, 200), (210, 200), (220, 200)]
snake_skin = pygame.Surface((10, 10))
snake_skin.fill((255, 255, 255))
my_direction = LEFT
apple = pygame.Surface((10, 10))
apple.fill((255, 0, 0))
apple_pos = on_grid_random()
clock = pygame.time.Clock()
while True:
    clock.tick(10)
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
        if collision(snake[0], apple_pos):
            apple_pos = on_grid_random()
            snake.append((0, 0))
        if event.type == KEYDOWN:
            if event.key == K_UP:
                my_direction = UP
            if event.key == K_DOWN:
                my_direction = DOWN
            if event.key == K_LEFT:
                my_direction = LEFT
            if event.key == K_RIGHT:
                my_direction = RIGHT
    if my_direction == UP:
        snake[0] = snake[0][0], snake[0][1] - 10
    if my_direction == DOWN:
        snake[0] = snake[0][0], snake[0][1] + 10
    if my_direction == LEFT:
        snake[0] = snake[0][0] - 10, snake[0][1]
    if my_direction == RIGHT:
        snake[0] = snake[0][0] + 10, snake[0][1]
    for i in range(len(snake) - 1, 0, -1):
        snake[i] = snake[i - 1][0], snake[i - 1][1]
    screen.fill((0, 0, 0))
    screen.blit(apple, apple_pos)
    for pos in snake:
        screen.blit(snake_skin, pos)
    pygame.display.update()

import pygame, random
from pygame.locals import *

UP = 0
RIGHT = 1
DOWN = 2
LEFT = 3

# FUNÇÃO DE CRIAR POSIÇÃO ALEATÓRIA NO GRID (ALINHADO)
def on_grid_random():
    x = random.randint(0,640)
    y = random.randint(0, 640)
    return (x//10 *10, y//10 *10)

# FUNÇÃO DE COLISÃO
def collision (c1,c2):
    return (c1 [0] == c2 [0]) and (c1 [1] == c2 [1])


# CRIAR A TELA INICIAL COM O NOME DO JOGO
pygame.init()
screen = pygame.display.set_mode ((650,650))
pygame.display.set_caption ('Snake')

# DEFINIR O SEGUIMENTO DA COBRA ATRAVÉS DE TUPLAS
snake = [(200,200), (210,200) , (220,200)]
# DEFINIR DIMENSẼS E COR DA COBRA
snake_skin = pygame.Surface((10,10))
snake_skin.fill((255,255,255))
# INDICAR A DIREÇÃO DA COBRA
my_direction = LEFT

# MAÇÃ PARA A COBRA COMER
apple = pygame.Surface((10,10))
apple.fill((255,0,0))
# GERAR UMA POSIÇÃO ALEATÓRIA PARA A MAÇÃ
apple_pos = on_grid_random()
# PARA COBRA SE MOVIMENTAR NUMA VELOCIDADE VISÍVEL
clock = pygame.time.Clock()

while True:
    clock.tick(10)
    # EVENTO PARA FECHAR A TELA DO JOGO
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()


        # A COLISÃO -> AUMENTAR A COBRA E GERAR UMA NOVA POSIÇÃO PARA A MAÇÃ
        if collision(snake [0], apple_pos):
            apple_pos = on_grid_random()
            snake.append((0,0))

        # PARA CONTROLAR A COBRA
        if event.type == KEYDOWN:
            if event.key == K_UP:
                my_direction = UP
            if event.key == K_DOWN:
                my_direction = DOWN
            if event.key == K_LEFT:
                my_direction = LEFT
            if event.key == K_RIGHT:
                my_direction = RIGHT


    # COMANDOS ATRAVÉS DE TUPLAS PARA MOVIMENTAÇÃO DA COBRA
    if my_direction == UP:
        snake[0] = (snake[0][0], snake [0][1] - 10)
    if my_direction == DOWN:
        snake[0] = (snake[0][0], snake[0][1] + 10)
    if my_direction == LEFT:
        snake[0] = (snake[0][0] -10 , snake[0][1])
    if my_direction == RIGHT:
        snake[0] = (snake[0][0] + 10, snake[0][1])

    # PARA MEXER O CORPO DA COBRA
    for i in range (len(snake) -1,0,-1):
        snake [i] = (snake [i-1][0], snake[i-1][1])






    screen.fill ((0,0,0))
    screen.blit (apple,apple_pos)
    for pos in snake:
        screen.blit(snake_skin,pos)

    pygame.display.update()
