You are on page 1of 15

Computer Project Report

By “Samyak Oswal”
Acknowledgement

I take this opportunity to express my sincere thanks


and gratitude to Mrs. Avnita Bir, Principal, R.N Podar school (C.B.S.E)
for providing the facilities and infrastructure for my
computer project.

- Samyak Oswal
Index:
● Hardware specification
● Software specification
● Project objective
● Project usage
● Project outline
● Flow chart
● Program specifications
● Source code
● Output
● References
Hardware Specifications:
This project was made on the system with the following
Configuration:
-intel i3 8th gen processor or higher
-windows 7 or higher
-Software Specification:
The following are the software specifications of the program:
Pycharm
Spyder
Pygame module
Project Objective:
Try your hardest to survive and thrive by eating fruits, which in turn makes you grow in size!
Project usage:
This project helps the player improve their hand-eye coordination
PROJECT OUTLINE
The snake game, is a game which requires your attention,control and time. The snake
will be controlled by the player using the arrow-keys. The game has a highly
competitive background and can be enjoyed amongst the comforts of friends. The
challenge is to attain the highest score. After one player does their best, the other can
take over to either beat it, or die trying.

Package used:- Pygame


Flowchart:
Start game

Control the snake and


follow the apple to grow.

If u die then restart or


Try not to touch border
quit

After all its just a game Do not touch ur own body


only for entertainment so after growing it otherwise
enjoy. u will lose.
Project specifications:
Snake is a video game that originated during the late 1970s in arcades becoming
something of a classic. It became the standard pre-loaded game on Nokia phones in
1998.

The whole code is based on easy steps starting with installing pygame, creating the
screen, snake, defining movement of the snake, defining game over criterias, adding the
food for the snake to grow, growth of the snake itself and at last displaying the score
which everyone loves to show-off about.
SOURCE CODE:
import pygame # display settings

import random dis_width = 600


dis_height = 400
pygame.init()

# color codes
# initialize screen
white = (255, 255, 255)
screen = pygame.display.set_mode((dis_width,
yellow = (255, 255, 102) dis_height))

black = (0, 0, 0) pygame.display.set_caption('Snake Game by


Samyak,Travis,Rehan')
red = (213, 50, 80)

green = (0, 255, 0)

blue = (50, 153, 213)


clock = pygame.time.Clock() def gameLoop():

game_over = False

game_close = False
# game settings

snake_block = 10 x1 = dis_width / 2

snake_speed = 15 y1 = dis_height / 2

x1_change = 0
font_style = pygame.font.SysFont("bahnschrift", 25)
y1_change = 0
score_font = pygame.font.SysFont("comicsansms",
35)
snake_List = []

snake_length = 1
food_x = round(random.randrange(0, dis_width - for event in pygame.event.get():
snake_block) / 10.0) * 10.0
if event.type == pygame.KEYDOWN:
food_y = round(random.randrange(0, dis_height
- snake_block) / 10.0) * 10.0 if event.key == pygame.K_q:

game_over = True
while not game_over:
game_close = False

if event.key == pygame.K_c:
while game_close:
gameLoop()
screen.fill(blue)
for event in pygame.event.get():
message("You Lost! Press 'C' to Play Again
or 'Q' to Quit", red)
if event.type == pygame.QUIT:
score_self(snake_length - 1)
game_over = True
pygame.display.update()
if event.type == pygame.KEYDOWN: if x1 >= dis_width or x1 < 0 or y1 >= dis_height or y1 < 0:
if event.key == pygame.K_LEFT:
game_close = True
x1_change = -snake_block
x1 += x1_change
y1_change = 0
y1 += y1_change
elif event.key == pygame.K_RIGHT:

x1_change = snake_block
screen.fill(blue)

y1_change = 0 pygame.draw.rect(screen, green, [food_x, food_y,


snake_block, snake_block])
elif event.key == pygame.K_UP:

y1_change = -snake_block
snake_Head = [x1, y1]

x1_change = 0 snake_List.append(snake_Head)

elif event.key == pygame.K_DOWN: if len(snake_List) > snake_length:


y1_change = snake_block
del snake_List[0]
x1_change = 0
for x in snake_List[:-1]: if x1 == food_x and y1 == food_y:

if x == snake_Head: food_x = round(random.randrange(0, dis_width


- snake_block) / 10.0) * 10.0
game_close = True food_y = round(random.randrange(0, dis_height
- snake_block) / 10.0) * 10.0
snake_self(snake_block, snake_List)
snake_length += 1
score_self(snake_length - 1)

clock.tick(snake_speed)

pygame.display.update()
pygame.quit()

quit()
def score_self(score): 3])
value = score_font.render("Your Score: " +
str(score), True, yellow) # Main function call

screen.blit(value, [0, 0]) gameLoop()

def snake_self(snake_block, snake_list):


for x in snake_list:
pygame.draw.rect(screen, black, [x[0], x[1],
snake_block, snake_block])
def message(msg, color):
msg_t = font_style.render(msg, True, color)
screen.blit(msg_t, [dis_width / 10, dis_height /
Output:
References:
https://www.youtube.com/watch?v=8dfePlONtls

https://www.pygame.org/news

You might also like