2
2
2
com
import pygame
import time
import random
pygame.init()
# Dimension of window
width = 600
height = 400
pygame.display.set_caption('Snake Game')
c = pygame.time.Clock()
snake_block = 10
snake_speed = 15
# Font style
def Your_score(score):
for x in snake_list:
def gameLoop():
game_over = False
game_close = False
x1 = width / 2
y1 = height / 2
x1_change = 0
y1_change = 0
snake_List = []
Length_of_snake = 1
# Game Loop
running = True
while running:
screen.fill((0, 0, 0))
pygame.display.update()
# Quit event
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x1_change -= snake_block
y1_change = 0
elif event.key == pygame.K_RIGHT:
x1_change += snake_block
y1_change = 0
y1_change -= snake_block
x1_change = 0
y1_change += snake_block
x1_change = 0
game_close = True
x1 += x1_change
y1 += y1_change
snake_Head = []
snake_Head.append(x1)
snake_Head.append(y1)
snake_List.append(snake_Head)
del snake_List[0]
for x in snake_List[:-1]:
if x == snake_Head:
game_close = True
snake(snake_block, snake_List)
Your_score(Length_of_snake - 1)
pygame.display.update()
#Checking same coordinates
Length_of_snake += 1
c.tick(snake_speed)
#quit event
pygame.quit()
quit()
gameLoop()