Snake Game 1 SRS Documentation PDF
Snake Game 1 SRS Documentation PDF
Bachelor of Technology
in
Computer Science and Engineering
by
Name
18N31A0XXX
Under the esteemed Guidance of
Mrs. P Honey Diana
Assistant Professor
(Affiliated to JNTUH, Hyderabad, Approved by AICTE, NBA &NAAC with ‘A’ Grade)
1
Malla Reddy College of Engineering & Technology
(Autonomous Institution- UGC, Govt. of India)
(Affiliated to JNTUH, Hyderabad, Approved by AICTE, NBA &NAAC with ‘A’ Grade)
CERTIFICATE
This is the bonafide record of the project entitled “SNAKE GAME”, submitted by
Name(18N31A0XXX) of B.Tech in the partial fulfillment of the requirements for the degree
of Bachelor of Technology in Computer Science and Engineering, Department of CSE during
the year 2020-2021. The results embodied in this project report have not been submitted to
any other university or institute for the award of any degree or diploma.
EXTERNAL EXAMINER
2
DECLARATION
I hereby declare that the project titled “SNAKE GAME” submitted to Malla Reddy College
of Engineering and Technology (UGC Autonomous), affiliated to Jawaharlal Nehru
Technological University Hyderabad (JNTUH) for the award of the degree of Bachelor of
Technology in Computer Science and Engineering is a result of original research carried-out
in this thesis. It is further declared that the project report or any part thereof has not been
previously submitted to any University or Institute for the award of degree or diploma.
Name
18N31A0XXX
3
ACKNOWLEDGEMENT
Presentation inspiration and motivation have always played a key role in the success of any
venture
I feel myself honored and privileged to place my warm salutation to our college Malla Reddy
College of Engineering and Technology and our Director Dr. VSK Reddy who gave us the
opportunity to have experience in engineering and profound technical knowledge.
I would like to express my gratitude to Dr. S Srinivas Rao, Principal, Malla Reddy College
of Engineering and Technology for his constant support and motivation.
I express my heartiest thanks to our Head of the Department Dr. D. Sujatha, Computer
Science and Engineering for encouraging us in every aspect of our project and helping us
realize our full potential.
I pay my deep sense of gratitude to Mrs. P Honey Diana Assistant Professor and Project
Coordinator to encourage me to the highest peak and to provide me the opportunity to prepare
the project. I am extremely grateful to her valuable suggestions and unflinching co-operation
throughout project work.
Last, but not least, my parents are also an important inspiration for me. So with due
regards, I express my gratitude to them.
Name
18N31A0XXX
4
ABSTRACT
The Project entitled ‘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 co-ordinates 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.
5
TABLE OF CONTENTS
CONTENTS PAGENO
1. INTRODUCTION TO PROJECT 8
2. LITERATURE SURVEY 9
3. MODULES 10
4.4.1.4 Scope 14
5.IMPLEMENTATION 16-20
6
5.1 PYTHON 16-17
5.2 PY-GAME 18
6.TESTING 21-23
22
6.2.5 Validation testing
22
6.2.6 System testing
22-23
6.3 TEST CASES
24
7.CONCLUSION AND FUTURE ENHANCEMENT
25
8.BIBLIOGRAPHY
7
Chapter 1: 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 a snake 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.
8
Chapter 2: 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 implementations. However, it was the 1980'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's. 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 eat an 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 eats himself the
game is over. The more blocks the snake eats the higher the score .
9
Chapter 3: MODULES
pygame
• Py game is a cross-platform set of python modules designed for writing video games.
It includes computer graphics and sound libraries designed to be used with the Python
Programming language.
• To install the library, you can use pip installer from the command line:
import pygame
import time
• Python has a built-in module that you can use to make random numbers.
import random
10
Chapter 4: SYSTEM DESIGN
Chapter 3: SY
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:
● A way of representing the snake
● A way of representing the food
● A way to display the score,
● a way for our instructions 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 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 snake 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 snake'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
11
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
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.
I.Robustness:
Robustness is nothing but its ability that it can tolerate the affects of system functional body. And it
can also be defined as its systems ability that it can withstand to change without transforming its
12
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 period of
time.
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 time.
IV.Reusability:
The system can be used any number of times by the specific user. And the reusability is consistent,
V.Effectiveness:
The algorithm is capable of producing desired result or it has the ability to provide better results.
13
into a formal document (the output of the requirement phase.) The SRS phase consists of two basic
activities:
4.4.1.4 Scope:
This document is the only one that describes the requirements of the system. It is meant for the use
by the developers, and will also be the basis for validating the final delivered system. Any changes
made to the requirements in the future will have to go through a formal change approval process.
The developer is responsible for asking for clarifications, where necessary, and will not make any
alterations without the permission of the client.
14
4.5.2 HARDWARE REQUIREMENTS
The development and deployment of the application requires the following general and specific
minimum requirements for hardware:
15
CHAPTER 5 : IMPLEMENTATION
5.1 PYTHON
Python is an object-oriented, high level language, interpreted, dynamic and multipurpose
programming language.
Python is easy to learn yet powerful and versatile scripting language which makes it attractive for
Application Development.
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 supports multiple programming pattern, including object oriented programming, imperative
and functional programming or procedural styles.
Python is not intended to work on special area such as web programming. That is why it is known
as multipurpose because it can be used with web, enterprise, 3D CAD etc.
We don't need to use data types to declare variable because it is dynamically typed so we can write
a=10 to declare an integer value in a variable.
Python makes the development and debugging fast because there is no compilation step included in
python development and edit-test-debug cycle is very fast.
Python History
• Python laid its foundation in the late 1980s.
• The implementation of Python was started in the December 1989 by Guido Van Rossum at
CWI in Netherland.
• 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
• Modula-3
16
Python Versions
Python programming language is being updated regularly with new features and support. There are
a lot of updation in python versions, started from 1994 to current date.
17
5.2 PY-GAME
Python is the most popular programming language or nothing wrong to say that it is the next-
generation programming language. In every emerging field in computer science, Python makes its
presence actively. Python has vast libraries for various fields such as Machine Learning (Numpy,
Pandas, Matplotlib), Artificial intelligence (Pytorch, TensorFlow), and Game development
(Pygame,Pyglet).
Game programming is very rewarding nowadays and it can also be used in advertising and as a
teaching tool too. Game development includes mathematics, logic, physics, AI, and much more and it
can be amazingly fun. In python, game programming is done in pygame and it is one of the best
modules for doing so.
o Pygame is a cross-platform set of Python modules which is used to create video games.
o It consists of computer graphics and sound libraries designed to be used with the Python
programming language.
o Pygame was officially written by Pete Shinners to replace PySDL.
o Pygame is suitable to create client-side applications that can be potentially wrapped in a
standalone executable.
Installing pygame:
The first thing you will need to do in order to create games using Pygame is to install it on your
systems. To do that, you can simply use the following command:
18
5.3 FUNCTION DESCRIPTION
Once that is done, just import Pygame and start our game development. Before moving on, take a
look at the Pygame functions that have been used in this Snake Game along with their descriptions.
Function Description
init() Initializes all of the imported Pygame modules (returns a
tuple indicating success and failure of initializations)
set_caption() Will set the caption text on the top of the display screen
font.SysFont() Will create a Pygame font from the System font resources
19
5.4 IMPLEMENTATION STEPS
1. Installing pygame
2. Create the screen
3. Create the Snake
4. Moving the Snake
5. Game over when snake hits the boundaries
6. Adding the Food
7. Increasing the length of the snake
8. Displaying the score
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.
6. If the snake is over food, eat it, increase the score, grow, move the food,
8. Go back to 4.
20
CHAPTER 6: TESTING
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, prevent frustration during
implementation process etc.,
21
6.2.3 Unit Testing:
Unit testing is essentially for the verification of the code produced during the coding phase
and the goal is test the internal logic of the module/program. In the Generic code project, the unit
testing is done during coding phase of data entry forms whether the functions are working properly
or not. In this phase all the drivers are tested 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 generic code integration testing is done mainly on table creation module and
insertion module.
How can we test a full Snake game and, assuming it passes that stage, how can we playtest that?
To display the snake, the first thing we want to do is to make sure that we can draw the snake and
move it around on the screen. So our testing for correct function will be:
22
3. Is it displaying correctly?
If we identify an error in the snake, because it's a Class, we will go into the Snake class and fix it
there. However, because we've written the Food and Scoreboard as separate classes, whatever we
do in the Snake class shouldn't break anything in there, unless we accidentally change the code
without noticing. The next step for the snake will be checking what happens when the head is
detected as colliding with something. Does it grow when it eats food? Does it die when it hits a wall
or itself? We'd then continue to test the program until we've tested all of the individual elements and
their interactions together.
One useful test case is to see if everything is being drawn where you expect. Because we aren't
using all the screen, it's possible to draw the food or the snake so that it overlaps the black rectangle
that's the boundary. Has the programmer put the correct limits on the ranges where the snake and
the food can appear?
Testing the non-functional requirements often falls into the realm of playability
Many snake games increase the speed of the snake as it gets longer, increasing the difficulty even
further. This increased movement speed gives a sense of urgency and can be a way to engage
players with the snake. But make it too fast and it becomes unplayable
23
CHAPTER 7: 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 co-ordinates 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
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 after
making some changes and modifications as I made this project at low level. The modifications that
can be done in this project are:
24
CHAPTER 8: BIBLIOGRAPHY
WEBSITES
• https://www.edureka.co/blog/snake-game-with-pygame/
• https://pypi.org/project/pygame/
• https://www.educba.com/python-pygame/
• https://www.w3schools.com/python/module_random.asp
• https://www.programiz.com/python-programming/time
25