Professional Documents
Culture Documents
Snake Game Mini - Project Format 2022-23
Snake Game Mini - Project Format 2022-23
Signature: Signature:
Name: Name:
Date: Date:
Signature: Signature:
Name: Name:
Date: Date:
Signature: Signature:
Name: Name:
Date: Date:
ii
CERTIFICATE
This is to certify that the Project Report entitled “ Snake Game ” which is submitted by Harsh
Kumar Yadav (223236), Aman Kumar Maurya (223238), Suraj Kumar Pandey (223236),
Suraj Kushwaha (223245), Shashwat Singh Gaur (223153), Ateefa Zainab (220350) of the
3th semester, in the year 2022-2023.
In partial fulfillment of the requirement for the award of degree of B.Tech in department of
Computer Science & Engineering of Dr. APJ Abdul Kalam Technical University is a record
of the candidate own work carried out by him/her under my supervision. The matter embodied in
this is original and is not been submitted for the award of any degree.
Signature Signature
(Mr. Rahul Singh) (NIHARIKA NISHAD)
(Head of Department) (Assistant Professor)
CSE Department CSE Department
KIT Kanpur KIT Kanpur
Date:
iii
ACKNOWLEDGEMENT
It gives us a great sense of pleasure to present the report of the B.Tech Project undertaken during
B.Tech Second Year. We owe special debt of gratitude to our guide Niharika Nishad of Department
of Computer Science & Engineering, Kanpur Institute of Technology, Kanpur (U.P) for his
constant support and guidance throughout course of our work. His sincerity, thoroughness and
perseverance have been a constant source of inspiration for us. It is only his cognizant efforts that our
endeavors have been light of the day.
We also take the opportunity to acknowledge the contribution of Mr. Rahul Singh , Head of
Department of Computer Science & Engineering, Kanpur Institute of Technology, Kanpur
(U.P.) for his full support and assistance during the development of the project.
We also do not like to miss the opportunity to acknowledge the contribution of all faculty members
of the department for their assistance and cooperation during the development of my project. Last but
not the least, we acknowledge our friends for their contributions in the completion of the project.
Signature: Signature:
Name: Name:
Date: Date:
Signature: Signature:
Name: Name:
Date: Date:
Signature: Signature:
Name: Name:
Date: Date:
iv
ABSTRACT
The Nokia inspired Snake game was implemented on 8051 platform. The
game is built on the AT89551 Microcontroller. The game uses an 8 8 LED
dot matrix display and five way keys for user interface. A dedicated delay
settings key provides one touch access to the delay settings mode where
the speed of the Snake can be adjusted.
v
TABLE OF CONTENTS
Title
Page
CERTIFICATE 01
ACKNOWLEDGEMENT 02
ABSTRACT 03
TABLE OF CONTENTS 04
LIST OF TABLES 05
LIST OF FIGURES 06
CHAPTER 1: INTRODUCTION 08
1 Introduction to the Project
CHAPTER 5: IMPLEMENTATION 21
5.1 Python
5.2 PY- charm
vi
5.3 Functional Descriptions
5.4 Implementation steps
5.5 Working Algorithm
5.6 Source Code
5.7 Screenshot of the game
RFERENCES 35
List Of Figures
vii
CHAPTER 1: INTRODUCTION
Playing games is fun and exciting. It gives us relief from stress and unwinds
from our stressful work. Many of us spend our free time or others that use most
of their time in playing and exploring new games. Today, with the raped
development of technology we have, games that are rising up together with it.
Nowadays with technology we have many games that are developed for
computers specifically for windows. With the high technology equipped with
these 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 a stake 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 (walls,
boundaries). As you collect the food, the stake gets longer. The score also
increases. There is no concept of life. Once you hit an obstacle, that's it, game
over.
CHAPTER 2: LITERATURE REVIEW
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 implementations. However, it was
the 1990's when the game took on the look that we will be using. It was sold under numerous
names and many platforms but probably gained widespread recognition when it was shipped
as standard on Nokia mobile phones in the late 1990' The first 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 left or right by
ninety degrees until you manage to cut a block. When you get the block, the Snake grows an
extra block or body segment.
If, or rather when, the snake bumps into the edge of the screen or accidentally casts himself
the game is over. The more blocks the snake eats the higher the score.
2.2 MODULES
PyCharm
A snake game is an arcade maze game which has been developed by Gremlin Industries and
published by Sega in October 1976. It is considered to be a skillful game and has been
popularized among people for generations. The snake in the Snake game is controlled using
the four direction buttons relative to the direction it is headed in. The player's objective in the
game is to achieve maximum points as possible by collecting food or fruits. The player loses
once the snake hits the wall or hits itself.
For the python beginners, those who are interested in making something easier in your
domain can definitely try this out and the module Turtle was made exactly for this purpose
for the beginners to try out and can also submit as a part of the project. This program will be
done in Python 3.
So, we will be creating a Python-based-game using the following modules:
• Turtle: It is a pre-installed python library that enables users to create shapes and pictures
by providing them with a virtual canvas.
• Time: This function is used to count the number of seconds elapsed since the epoch.
• Random: This function is used to generate random numbers in Python by using random
module.
Support
The following code can be easily done using pycharm application which is specially made
for python programs.
The problem is to design a Snake Game which provides the following functionalities:
1. Snakes can move in a given direction and when they eat the
food, the length of the snake increases.
2. When the snake crosses itself, the game will be over.
3. Food will be generated at a given interval.
The main classes that can be used are:
10
1. Snake
2. Cell
3. Board
4. Game
11
3.4 OBEJECTIVE
Snake game is one of the most popular arcade games of all time. In this game, the main
objective of the player is to catch the maximum number of fruits without hitting the wall or
itself. Creating a snake game can be taken as a challenge while learning Python or Pygame.
It is one of the best beginner - friendly projects that every novice programmer should take as
a challenge.
12
CHAPTER 4: SYSTEM DESIGN
To create a Snake game that allows users to control the movement of a snake on a screen, to
get points for eating 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 representation 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:
1. A way of representing the sake of representing the food.
2. A way to display the score,
3. A way for our instructions to reach the snake
4. A way to know when we've run into something and died
Our system is going to involve working with both hardware and software, and so we will
need to understand what we have available in hardware that can assist us.
If we build our software 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 starting the design of our software system.
• We are going to use an object-oriented approach and provide some detail here. We have to
think about the Classes that we want to build, with the associated variables and functions that
will make sense for the development.
Let's start by looking at the snake itself, the hero of the game. The stake has a location on the
screen, and contains multiple visual elements, as it can grow, and the snake's head is
connected to the rest
of the snake and the stake's body follows it around the screen. If the snake "eats" food, it
grows. The snake moves in a very precise way. Based on what the user types, the snake will
move in a given direction. Every time the snake moves, the head will go in the new direction,
and every piece of the snake will move up, by occupying the space that was formerly
occupied by the piece in front of it.
To grow in size, the snake has to eat food. How can we show the snake eating? The simplest
answer is that if the head of the snake and the food are in the same place, we consider that
the snake eats the food. This means that we have to know where the food is. When it's eaten,
it disappears, the snake grows, and the food shows up somewhere else. But we also wanted
to show a score, so we need a variable to keep track of that as well. In this case, we'll create a
Scoreboard class where we can increase the counter value and display it.
13
4.2 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 to the walls
5. The snake never stops moving
Robustness:
Robustness is nothing but its ability to tolerate the effects of the system's fictional body. And
it can also be defined by its system's ability that it can withstand change without
transforming its initial stable configuration.
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
period of
Availability:
The system is available 247, Availability and Reliability are directly proportional as
reliability increases availability also increases. The ser can have access to the system all the
time
Reusability:
The system can be used any number of times by the specific user. And the reusability is
consistent, adaptable and stable
Effectiveness:
The algorithm is capable of producing desired results or it has the ability to provide better
results.
14
4.4 SOFTWARE REQUIREMENT SPECIFICATION
4.4.1 SRS
Software Requirement Specification (SRS) is the starting point of the software developing
activity. As the system grew more complex it became evident that the goal of the entire
system cannot be easily comprehended. Hence the need for
the requirement phase arose. The software project is initiated by the client. The SRS is the
means of translating the ideas of the minds of clients (the input) into a formal document (the
output of the requirement phase) The SRS phase consists of the activities.
The process is order and more nebulous of the two, deals with understanding the problem,
the constraints.
Here, the focus is on specifying what has been found giving analysis such as representation ,
specification languages and tools, and checking the specifications are addressed during this
The Requirement phase terminates with the production of the validate SS document.
Producing the SRS document is the basic goal of this phase.
The purpose of the Software Requirement Specification is to reduce the communication gap
between the clients and developers. Software Requirement Specification is the medium
which makes sure which the client and user needs are accurately specified. It forms the basis
of software development.
A good SRS should satisfy all the parties involved in the system.
The SRS document is the basic goal of this phase. The purpose of the Software Requirement
Specification is to reduce the communication gap between the clients and the developers.
The developer is responsible for asking for clarifications, where necessary, and will not
make alterations without the permission of the client.
The development and deployment of the application requires the following general and
specific minimum requirements for software:
Py charm
15
4.5.2 Hardware Requirements
The development and deployment of the application requires the following general and
specific minimum requirements for hardware:
Processor-(32-bit or 64-bit) RAM (4 GB).
16
CHAPTER 5: IMPLEMENTATION
5.1 PYTHON
Python's syntax and dynamic typing with its interpreted nature, make it an ideal language for
scripting and rapid application development in many areas
Python History
Python laid its foundation in the late 1980s.. The implementation of Python was started in
December 1989 by Guido Van Rossum CWI in the Netherlands.
ABC programming language is said to be the predecessor of Python language which was
capable of Exception Handling and interfacing with Amoeba Operating System.
Python is influenced by programming languages like
ABC language.
17
Method Parameter Description
fillcolor() Color name Changes the color of the turtle will use to fill a polygon
end_fill() None Close the polygon and fill with the current fill color
18
5.4 IMPLIMANTATION STEPS
Installing PY charm
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 I
2. Draw the snake in a starting position,
3. Draw the food in a starting location.
4. On user input, change snake direction.
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 step 4
9. Until the snake die
19
5.6 SOURCE CODE
# importing libraries
import turtle
import random
import time
turtle.speed(5)
turtle.pensize(4)
turtle.penup()
turtle.goto(-310, 250)
turtle.pendown()
turtle.color('black')
turtle.forward(600)
turtle.right(90)
turtle.forward(500)
turtle.right(90)
turtle.forward(600)
turtle.right(90)
turtle.forward(500)
turtle.penup()
turtle.hideturtle()
# score
score = 0
delay = 0.1
# snake
snake = turtle.Turtle()
snake.speed(0)
snake.shape('square')
snake.color("black")
snake.penup()
snake.goto(0, 0)
snake.direction = 'stop'
20
# food
fruit = turtle.Turtle()
fruit.speed(0)
fruit.shape('circle')
fruit.color('red')
fruit.penup()
fruit.goto(30, 30)
old_fruit = []
# scoring
scoring = turtle.Turtle()
scoring.speed(0)
scoring.color("black")
scoring.penup()
scoring.hideturtle()
scoring.goto(0, 300)
scoring.write("Score :", align="center", font=("Courier", 24, "bold"))
def snake_go_down():
if snake.direction != "up":
snake.direction = "down"
def snake_go_left():
if snake.direction != "right":
snake.direction = "left"
def snake_go_right():
if snake.direction != "left":
snake.direction = "right"
def snake_move():
if snake.direction == "up":
y = snake.ycor()
21
snake.sety(y + 20)
if snake.direction == "down":
y = snake.ycor()
snake.sety(y - 20)
if snake.direction == "left":
x = snake.xcor()
snake.setx(x - 20)
if snake.direction == "right":
x = snake.xcor()
snake.setx(x + 20)
# Keyboard bindings
screen.listen()
screen.onkeypress(snake_go_up, "Up")
screen.onkeypress(snake_go_down, "Down")
screen.onkeypress(snake_go_left, "Left")
screen.onkeypress(snake_go_right, "Right")
# main loop
while True:
screen.update()
# snake and fruit coliisions
if snake.distance(fruit) < 20:
x = random.randint(-290, 270)
y = random.randint(-240, 240)
fruit.goto(x, y)
scoring.clear()
score += 1
scoring.write("Score:{}".format(score), align="center", font=("Courier", 24, "bold"))
delay -= 0.001
## creating new_ball
new_fruit = turtle.Turtle()
new_fruit.speed(0)
new_fruit.shape('square')
new_fruit.color('red')
new_fruit.penup()
old_fruit.append(new_fruit)
old_fruit[index].goto(a, b)
if len(old_fruit) > 0:
a = snake.xcor()
b = snake.ycor()
old_fruit[0].goto(a, b)
snake_move()
## snake collision
for food in old_fruit:
if food.distance(snake) < 20:
time.sleep(1)
screen.clear()
screen.bgcolor('turquoise')
scoring.goto(0, 0)
scoring.write(" GAME OVER \n Your Score is {}".format(score), align="center",
font=("Courier", 30, "bold"))
time.sleep(delay)
turtle.Terminator()
23
OUTPUT SCREEN :
24
25
CHAPTER 6: TESTING
6.1 SOFTWARE TESTING
Software testing is a critical element of software quality assurance and represents the
ultimate review of specification, design and code generation
To ensure that during operation the system will perform as per specification. To make
sure that system meets the user requirements during operation
To make sure that during the operation, incorrect input, processing and output will be
detected. To see that when correct inputs are fed to the system the outputs are correct
To verily that the controls incorporated in the same system as intended
A good test case is one that has a high probability of finding an as yet undiscovered
The software developed has been tested successfully using the following testing strategies
and any errors that are encountered are corrected and again the part of the program or the
procedure of function is put to testing until all the errors are removed. A successful test is
one that uncovers an as yet undiscovered error.
Note that the result of the system testing will prove that the system is working correctly,
It will give confidence to system designer, users of the system.
White box testing is a testing case design method that uses the control structure of the
procedure design to derive test cases. All independent paths in a module are exercised at
least once. I logical decisions are exercised at once, execute all loops at boundaries and
within their operational bounds exercise internal data structure to ensure their validity. Here
the customer is given three chances to enter a valid choice out of the given menu. After
which the control exits the current menu.
Black Box Testing attempts to find errors in following areas or categories, incorrect or
missing. functions interface error, errors in data structures, performance error and
26
initialization and termination error. Here all the input data must match the data type to
become a valid entry.
Unit testing is essentially for the verification of the code produced during the coding phase
and the goal is to test the internal logic of the module program. In the Genetic code project,
the unit testing is done during the coding phase of data entry forms whether the functions are
working properly or not. In this phase all the drivers are tested whether they are rightly
connected or not.
All the tested modules are combined into sub systems, which are then tested. The goal is to
see if the modules are properly integrated, and the emphasis being on the testing interfaces
between the modules. In the genetic code integration testing is done mainly on table creation
modules and insertion modules.
This testing concentrates on confirming that the software is error-free in all respects. All the
specified validations are verified and the software is subjected to hard core testing. It also
aims at determining the degree of deviation that exists in the software designed from the
specification, they are listed out and are corrected
This testing is a series of different tests whose primary is to fully exercise the computer-
based system. This involves
Implementing the system in a simulated production environment and testing it.
Introducing errors and testing for error handling.
27
CHAPTER 7: CONTRIBUTION OF THE PROJECT TO THE SOCIETY
Snake is a classic game that requires players to assess their surroundings and find the
quickest or safest route to a point. This is an excellent opportunity to learn about spatial
awareness and plan ahead to your next move.
The classic game is infamous for using your own success against you when you become so
long that you get in your own way. Whilst many games and activities can teach your child
about vital life skills, there are not many that would educate on long term strategic planning.
As many parents will know, it can be extremely frustrating to reach such a high level and
then lose as you crash into your own tail. The game requires patience in order to grow and a
cool head once you inevitably lose. These are all valuable skills to learn early on in a child's
life that will benefit them in later years.
Snake is a tool that can be used as an educational helping hand. One of the important parts of
learning is that you will never get something right the first time. Snake teaches children that
practice makes perfect when it comes to learning new skills.
28
CHAPTER 8: CONCLUSIONS
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 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 be 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
relatively simple python programming, and perhaps the basis by which to extend the
principles and create more interesting games on your own.
LIMITATIONS:
⚫ The existing system only provides a text-based interface, which is not as user-friendly as
Graphical user Interface.
⚫The transactions are executed in off-line mode, hence on-line data capture and
modification is not possible.
THANK YOU
29