1.1general Introduction: Snake Game
1.1general Introduction: Snake Game
CHAPTER 1
1.INTRODUCTION
1.1General Introduction
Project documentation is concerned with describing the delivered software product, in this
case the snake game project. Project documentation includes user documentation which tells
users how to use the software product and system documentation which is principally
intended for further development and understanding. Project
1.2Problem system
The name of the game is “Snake game”. It’s a one type game which can be played in the
same machine. In this game we use four 5,1,0,&3 to control the snake direction. And when
pass any key game start and when the snake hit border the game is over.
1.3Feasibility study
A feasibility study evaluates the project’s potential for success; therefore, perceived
objectivity is an important factor in the credibility of the study for potential investors
and lending institutions. There are five types of feasibility study there are-
1. Technical Feasibility
2. Economic Feasibility
3. Legal Feasibility
4. Operational Feasibility
5. Scheduling Feasibility
CHAPTER 2
2. REVIEW OF LITERATURE
2.1Review Summary
The Mini Project in C Snake Game is a simple console application without graphics.
In this project, you can play the popular “Snake Game” just like you played it else
where. You have to use the 5,1,3 and 0 to move the Snake.
Food 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.
The source code for Snake Game in C is complete and totally error free. It is compiled in
Code::blocks using gcc compiler. The code is about 180 line source code, another type of
function are used and header file are used.
CHAPTER 3
3.SYSTEM CONFIGURATION
CHAPTER 4
4.MODULE DESCRIPTION
4.1 Module1
1.Game Attributes:-The name of the game is “Snake Game”. It’s a one type game which
can be played in the same machine. In this game we use four 5,1,3 and 0 to control the snake
direction. And when press any key game start and when the snake hit border the game is
over.
2.System Architecture:-System architecture defines the working methodology of the game
and shows the components, their relationships and how they evolve to make the game work.
The system architecture of this particular game can be divided into two parts:
Game components.
Game architecture.
2.1 Game Components:-Game Components are behind the scene methods which make up
the game and all the functionalities. The components are mesh together and there are lot of
inter relationships between them. The main components are:
void setup():-The setup function we used for generate the food and snake different co-
ordinate. In this function we used the rand().The rand() create the different co-ordinate.
void input():-The input function is used to control the snake inside the boundary which is
used to draw food. Here food is randomly generated. When the snake eat food they become
grow.
void makelogic():-In this function the main snake game logic is used.
2.2 Game Architecture:-The Game Architecture is the simplified graphical view of the
game. It shows how the components work and the basic view of the game at action. The
architectural view of the game is very important. Simply it gives an overview of the game
functionality and it makes the game easy to understand.
START
Please
any key
to
Start
Do you
want to
continue
?
STOP
CHAPTER 5
5.SYSTEM DESIGN
5.1 Data Flow Diagram (DFD):-Data Flow Diagrams originated with Chris Gane and Trish
Sarson in 1997, Who popularized the technique for structured analysis and design. Edward
Yourdon and Tom DeMarco introduced another method in the 1980s which used circles
instead rectangles to denote processes and which became popular.
A data Flow Diagram (DFD) is a graphical representation of the “flow” of data
through an information system, modeling its process aspects. A DFD is often used as a
preliminary step to create an overview of the system without going into great detail, which
can later be elaborated.
It is pictorial representation of Business processes (function/services/activities), along
with the data flow.
Software process:-Guides how the software is being build.
Business process:-Specific to organization.
In this focus is on what data flows and not how the data flows. When all the analysis is
being made then we develop a diagram to depict the analysis, and following are being
used:-
SYMBOL MEANING
Process
External Entity
Data Item
0 Level DFD
ADMINISTRATIO
Provides Authentication
GAME
CONSOL
PLAYER
1 Level DFD
Request
Give input For input
Output
Working
Process
CHAPTER 6
6.SYSTEM IMPLEMENTATION
6.1 Implementation:-
6.1.1 Game Construction:-Here we develop the game and test the game and ultimately play
the game. Construction phase can be divided into 2 phase:
Building the Game
Game play
6.1.2 Building the Game:-It’s the headrest part in all the line of process. When we first start
the game we first planning, find out the requirements, draw the architecture. To build the
game need to know programming language.
The development phases are:
Creating a single Snake.
Creating a Food.
Snake collision with food.
Snakes collision with each other body.
Snakes don’t move two direction at a same time.
6.1.3 Game Play:-The step of game play are given below:-
Open the game application:
Figure 6.1.2
Department of MCA, NHCE 2018-2019 11
Snake Game USN:1NH18MCA29
Figure 6.1.3
Figure 6.2.1
Figure 6.2.2
random function:-In c program there is a random function which is used to place the food at
any point on the screen. Moving snake in the screen, As you can see snake is printed by
printing ''@'' on the screen. Thus,we need to print the one character at the beginning and
erasing one character at the end.
Changing Direction:-The direction of snake can be changed using kbhit() function .when
you press the character accordingly it will change the direction of the snake.
Increasing size of snake:-When snake moves forward it's size increases and when the
coordinate of snake match with food coordinate then the size of snake is increased.
Increasing score:-when snanke get's the food the score of the user is also increased.
Figure 6.2.3
When snake touch the boundary of the screen. The game over will come. This can be done by
comparing the coordinate of boundary with the snake co-ordinate.
Figure 6.2.4
Last step ask user if he wants to continue playing or not. suppose we want to continue the
game we press the “y” then press the enter and the game is start.If we want to quit the game
Department of MCA, NHCE 2018-2019 14
Snake Game USN:1NH18MCA29
press any key then press enter.
6.3SAMPLE CODING:-
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int width=20,hight=20,gameover;
int x,y,fruitx,fruity,score,flag;
int tailx[100],taily[100];
int counttail=0;
void setup()
{
gameover=0;
x=width/2;
y=hight/2;
label1:
fruitx=rand()%20;
if(fruitx==0)
goto label1;
label2:
fruity=rand()%20;
if(fruity==0)
goto label2;
score=0;
}
void draw()
{
int i,j,k;
system("cls");
for(i=0;i<width;i++)
switch(flag)
{
case 1:
y--;
break;
case 2:
y++;
break;
case 3:
x--;
break;
case 4:
x++;
break;
default:
break;
}
if(x<0||x>width||y<0||y>hight)
gameover=1;
for(i=0;i<counttail;i++)
{
if(x==tailx[i] && y==taily[i])
gameover=1;
Department of MCA, NHCE 2018-2019 18
Snake Game USN:1NH18MCA29
}
if(x==fruitx && y==fruity)
{
label3:
fruitx=rand()%20;
if(fruitx==0)
goto label3;
label4:
fruity=rand()%20;
if(fruity==0)
goto label4;
score+=10;
counttail++;
}
}
int main()
{
int m,n;
char c;
label5:
setup();
while(!gameover)
{
draw();
input();
makelogic();
for(m=0;m<1000;m++)
{
for(n=0;n<1000;n++)
{
}
}
Department of MCA, NHCE 2018-2019 19
Snake Game USN:1NH18MCA29
for(m=0;m<1000;m++)
{
for(n=0;n<1000;n++)
{
}
}
}
printf("\n press y to continue again:");
scanf("%c",&c);
if(c=='y'||c=='Y')
goto label5;
printf("\n 5.FOR UP MOVING");
printf("\n 0.FOR DOWN MOVING");
printf("\n 1.FOR LEFT MOVING");
printf("\n 3.FOR RIGHT MOVING");
return 0;
}
CHAPTER 7
6. SOFTWARE TESTING
Software testing is process finding error from the program. To make our software error free
it should be done. Until we check the software testing we can‟t say where the error exactly
is, for successfully run the program it must be checked.
Principle of testing:-
• Unit testing:-It is the first level of testing. In unit testing smallest part of program
needs to be checked by independently.
• Integration Testing:- It is the second level of testing. In integration testing it‟s find
out the correctness of the program.
• Validation testing:- Validation testing follows integration testing. The distinction
between conventional and object-oriented software disappears. Focuses on user-
visible actions and user-recognizable output from the system. Demonstrates
conformity with requirements.
• Black box testing:-In black box testing we have to check external structure of the
software. You can‟t see the internal structure of the software. If you give input and
based on your input your desirable output come out then it is perfect otherwise
you have to fix it.
• White box testing:-In black box testing we have to check internal structure of the
software. Sometimes it is known by Glass box testing. Every independent path must
be checked at least one time. All loops and boundaries should be checked.
• System testing : -Types of System Testing :
CHAPTER 8
8.1Conclusion :-
This project gives us more thrilling, frustrating and also gives us more pleasure. It helps us in
many sectors like- planning, designing, developing, managing, programming skill, socket
programming and so on.
8.2Future Enhancements:-
Our project will be able to implement in future after making some changes and modifications
as we make our project at very low level.So the modifications that can be done in our project
are:IT can be made with good graphics.And we can add more options.
CHAPTER 9
9.REFERENCES
[1] http://www.csharpcorner.com/UploadFile/udeshikah/snake
-game-application-in-C-Sharp/
[2] http://www.dreamincode.net/forums/topic/243537-control-
issue-with-snake-game-in-c%23/
[3] http://csharp.netinformations.com/communications/csharp
-chat-client.htm