0% found this document useful (0 votes)
32 views27 pages

Untitled Document

The document provides details about a snake game project including: 1. An introduction describing the classic snake game and the goal to recreate it in Python. 2. An algorithm outline describing how the game would work with the snake moving in response to input and growing or dying based on eating food or hitting walls. 3. A sample output showing the code and output of the snake game program with the snake moving around the screen as food is eaten.

Uploaded by

indianhawkye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views27 pages

Untitled Document

The document provides details about a snake game project including: 1. An introduction describing the classic snake game and the goal to recreate it in Python. 2. An algorithm outline describing how the game would work with the snake moving in response to input and growing or dying based on eating food or hitting walls. 3. A sample output showing the code and output of the snake game program with the snake moving around the screen as food is eaten.

Uploaded by

indianhawkye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Project Report

(on Snake Game)


INDEX

Sr. No. Topics Page No.

1 Abstract

2 Introduction

3 Literature Survey

4 DesignSystem
5 System and Hardware
Requirements

6 Functional Requirements

7 Non-Functional
Requirements
8 Working Algorithm

9 Sample Output

10 Conclusion

11 Future Scope
ABSTRACT

Snake game is a simple console application


without graphics. In this project,you can play
the popular “Snake Game” just like you played
it elsewhere. You have to use the up, down,
right or left arrows to move the snake. Foods
are provided at the several coordinates of the
screen for the snake to eat. Every time the
snake eats the food, its length will by increased
by one element along with the score.
I have used Python as Programming language
for writing the code for the project and Jupyter
Notebook for writing the programs. Operating
system used Windows 10.
● Highlight
● Add Note
● Share Quote
INTRODUCTION
Playing games is fun and exciting it gives us
relief from stress and unwind from our stressful
works. Many of us spend our vacant time
or others that use most of their time in playing
and exploring new games. Today, with the rapid
development of technology we have, games
that are rising up together with it. Nowadays
with the technology we have many games that
are developing for computer most specifically
for windows. With the high technology equipped
with these computers, computer games
become robust and attract many people to buy
or have this gadget for them to experience
what’s inside it which makes it a trend for the
new generation of gadget.
Snake game is a computer action game; whose
goal is to control asnake to move and collect
food in a map. It has been around since the
earliest days of home computing and has
re-emerged in recent years on mobile phones.
It isn’t the world’s greatest game, but it does
give you an idea of what you can achieve with a
simple python program, and perhaps the basis
by which to extend the principles and create
more interesting games on your own.

To move the snake, use ‘up arrow’ for up, ‘down


arrow’ for down, ‘left arrow’ for left and ‘right
arrow’ for right. Press ‘Q’ to exit the game at
any time, press ‘C’ to continue the game.
The aim of the game is to collect the dots (food)
and avoid the obstacles (crosses borders). As
you collect the food, the snake gets longer. The
score also increases. There is no concept of
lives. Once You hit an obstacle, that’s it, game
over.
LITERATURE SURVEY

The history of the Snake game goes back to the


1970's, the concept originated in the 1976
arcade game Blockade, and its simplicity has
led to many implementaons. However, it was
the 1980'swhen the game took on the look that
we will be using. It was sold under numerous
names and many plaorms but probably gained
widespread recognion when it was shipped as
standard on Nokia mobile phones in the late
1990's. The rst published Nokia, for
monochrome phones. It was programmed in
1997 by Taneli Armanto of Nokia and
introduced on the Nokia 6110.The game
involves controlling a single block or snakehead
by turning only le or right by ninety degrees unl
you manage to eat an block. When you get the
block, the Snake grows an extra block or body
segment. If, or rather when, he snake bumps
into the edge of the screen or accidentally eats
himself the game is over.
SYSTEM DESIGN

To create a Snake game that allows users to


control the movement of a snake on a screen,
to get points for eang food and avoiding running
into the walls or the growing tail of the snake
itself. In this problem, we want to write a game
where a graphical representa on of a snake
moves across The screen. When it encounters
a piece of food, the snake grows
longer and we gain a point. If it hits the wall we
die. To write this program we are going to need:
● A way of represenng the snake
● A way of represenng the food
● A way to display the score,
● A way for our instrucons to reach the snake,
and a way to know when we’ve run into
something and died Our system is going to
involve working with both hardware and
soware, and so we will need to understand
what we have available in hardware that can
assist us. If we build our soware so that the
snake is controlled by directional arrows on the
keyboard.

Now that understand how our hardware will


work in the design of our system, let’s move on
to strong the design of our software system.
SYSTEM AND HARDWARE
REQUIREMENTS
SYSTEM REQUIREMENTS
OPERATING SYSTEM : WINDOWS XP or
Higher
IDE : VisualStudio.
FRONT END : WINDOWS
LANGUAGE : Python
HARDWARE REQUIREMENTS
Intel P4 2.0GHz or above
2GB RAM
80GB HDD Minimum
FUNCTIONAL REQUIREMENTS

Here are the requirements (functional


requirements) for how the snake moves.

1. The snake must appear to move around the


screen.

2. The snake must turn in response to user


input.

3. The snake will increase in length if it eats


food.

4. The snake will die if it runs into the walls.

5. The snake never stops moving.


NON-FUNCTIONAL REQUIREMENTS

The primary features of IT projects involve


implementing like an application, a piece of
infrastructure, a patch. In this specific context
functional requirements tells us about what
project does when interacted, whereas
non-functional requirements describe about the
bounds of performance should be.Robustness :
Robustness is nothing but its ability that it can
tolerate the acts of system functional body. And
it can also be defined as its systems
ability that it can withstand to change without
transforming its initial stable configuration.

II. Reliability:

The system is trustworthy and it is consistently


good in performance.It can also be stated as
the system performs the function without any
failure under certain conditions and specified
periods for me.
III. Availability:

The system is available 24*7. Availability and


Reliability are directly proportional as reliability
increase availability also increases. The user
can have access to the system all the me.

IV. Reusability:

The system can be used any number of mes by


the specific user. And the reusability is
consistent, adaptable and stable.

V. Effectiveness:

The algorithm is capable of producing desired


result or it has the ability to provide beer results.
WORKING ALGORITHM

Let's look at how a program to run the whole


game might look:

1.Draw the playing area with bounding


rectangle, set the counter to
zero and display it.
2. Draw the snake in a string position.
3. Draw the food in a string location.
4. On user input, change snake direcon.
5. Move the snake one move
6. If the snake is over food, eat it, increase the
score, grow, move the food,
7. else if the snake is over in a wall, die.
8. Go back to 4.
9. Unl the snake die
SAMPLE OUTPUT
Source Code

import turtle
import time
import random

delay = 0.1

# Score
score = 0
high_score = 0

# Set up the screen


wn = turtle.Screen()
wn.title("Snake Game by Sakshi")
wn.bgcolor("green")
wn.setup(width=600, height=600)
wn.tracer(0) # Turns off the screen updates

# Snake head
head = turtle.Turtle()
head.speed(0)
head.shape("square")
head.color("black")
head.penup()
head.goto(0,0)
head.direction = "stop"

# Snake food
food = turtle.Turtle()
food.speed(0)
food.shape("circle")
food.color("red")
food.penup()
food.goto(0,100)

segments = []
# Pen
pen = turtle.Turtle()
pen.speed(0)
pen.shape("square")
pen.color("white")
pen.penup()
pen.hideturtle()
pen.goto(0, 260)
pen.write("Score: 0 High Score: 0", align="center", font=("Courier", 24,
"normal"))

# Functions
def go_up():
if head.direction != "down":
head.direction = "up"

def go_down():
if head.direction != "up":
head.direction = "down"

def go_left():
if head.direction != "right":
head.direction = "left"

def go_right():
if head.direction != "left":
head.direction = "right"

def move():
if head.direction == "up":
y = head.ycor()
head.sety(y + 20)

if head.direction == "down":
y = head.ycor()
head.sety(y - 20)

if head.direction == "left":
x = head.xcor()
head.setx(x - 20)
if head.direction == "right":
x = head.xcor()
head.setx(x + 20)

# Keyboard bindings
wn.listen()
wn.onkeypress(go_up, "w")
wn.onkeypress(go_down, "s")
wn.onkeypress(go_left, "a")
wn.onkeypress(go_right, "d")

# Main game loop


while True:
wn.update()

# Check for a collision with the border


if head.xcor()>290 or head.xcor()<-290 or head.ycor()>290 or
head.ycor()<-290:
time.sleep(1)
head.goto(0,0)
head.direction = "stop"

# Hide the segments


for segment in segments:
segment.goto(1000, 1000)

# Clear the segments list


segments.clear()

# Reset the score


score = 0

# Reset the delay


delay = 0.1

pen.clear()
pen.write("Score: {} High Score: {}".format(score, high_score),
align="center", font=("Courier", 24, "normal"))
# Check for a collision with the food
if head.distance(food) < 20:
# Move the food to a random spot
x = random.randint(-290, 290)
y = random.randint(-290, 290)
food.goto(x,y)

# Add a segment
new_segment = turtle.Turtle()
new_segment.speed(0)
new_segment.shape("square")
new_segment.color("grey")
new_segment.penup()
segments.append(new_segment)

# Shorten the delay


delay -= 0.001

# Increase the score


score += 10

if score > high_score:


high_score = score

pen.clear()
pen.write("Score: {} High Score: {}".format(score, high_score),
align="center", font=("Courier", 24, "normal"))

# Move the end segments first in reverse order


for index in range(len(segments)-1, 0, -1):
x = segments[index-1].xcor()
y = segments[index-1].ycor()
segments[index].goto(x, y)

# Move segment 0 to where the head is


if len(segments) > 0:
x = head.xcor()
y = head.ycor()
segments[0].goto(x,y)
move()

# Check for head collision with the body segments


for segment in segments:
if segment.distance(head) < 20:
time.sleep(1)
head.goto(0,0)
head.direction = "stop"

# Hide the segments


for segment in segments:
segment.goto(1000, 1000)

# Clear the segments list


segments.clear()

# Reset the score


score = 0

# Reset the delay


delay = 0.1

# Update the score display


pen.clear()
pen.write("Score: {} High Score: {}".format(score,
high_score), align="center", font=("Courier", 24, "normal"))

time.sleep(delay)

wn.mainloop()
CONCLUSION

The project in python programming of Snake


Game is a simple console application with very
simple graphics. In this project, you can play
the popular “Snake Game” just like you played
it elsewhere. You have to use the up, down,
right, or le arrows to move the snake. Foods are
provided at the several coordinates of the
screen for the snake to eat. Every me the snake
eats the food, its length will increased by one
element along with the score.It isn’t the world’s
greatest game, but it does give you an idea of
what you can achieve with a relatively simple
python programming,and perhaps the basis by
which to extend the principles and create more
interesting games on your own.
FUTURE SCOPE

In this project, I have used simple application,


this project will be able to implement in future
aer making some changes and modifications as
I made this project at low level.

The medications that can be done in this project


are:
1. It can be made with good graphics.
2. We can add more options like Top scores
and Player Prole.
3. We can add multiplayer option.
REFERENCE :
1)hps://data-air.training/blogs/snake-game-pyth
on-program/
2)https://gist.github.com/wynand1004/ec105fd2f
457b10d971c09586ec
3)tutle.py

You might also like