SlideShare une entreprise Scribd logo
1  sur  15
OF 
Snake game 
Submitted in the partial fulfillment of the Degree of Bachelor of Technology 
(Integrated) 
In 
Computer Science and Engineering 
SUBMITTED BY:- GUIDED BY: 
Name Ankit&uttkarsh Miss Sukhdilpreet Kaur 
Regd. No 10801409, 10800775 
Rollno (complete)R246B34&R246B35 
SUBMITTED TO 
Department of Computer Science and Engineering Lovely Professional University 
Phagwara
ACKNOWLEDGEMENT 
I take this opportunity to present my votes of thanks to all those guidepost who really 
acted as lightening pillars to enlighten our way throughout this project that has led to 
successful and satisfactory completion of this study. 
We are really grateful to our HOD Mr. Rohit Dhand for providing us with an 
opportunity to undertake this project in this university and providing us with all the 
facilities. We are highly thankful to Miss Sukhdilpreet Kaur for her active support, 
valuable time and advice, whole-hearted guidance, sincere cooperation and pains-taking 
involvement during the study and in completing the assignment of preparing 
the said project within the time stipulated. 
Lastly, We are thankful to all those, particularly the various friends , who have been 
instrumental in creating proper, healthy and conductive environment and including 
new and fresh innovative ideas for us during the project, their help, it would have 
been extremely difficult for us to prepare the project in a time bound framework. 
Name Ankit chopra 
uttkarsha singh 
10800775 Regd.No10801409 
R246B35 
RollnoR246B34.
TABLE OF CONTENTS 
1. Introduction 
2. Proposed system 
i. Description 
ii. System requirements 
3. Requirement Analysis 
4. System Design 
5. Source code 
6. Testing 
7. Future scope of project
INTRODUCTION 
The following is an example game written in C based on the game called 
'snake' which has been around since the earliest days of home computing (I 
can remember writing a version of it for my ZX81), 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 relatively simple C program, and perhaps the basis by 
which to extend the principles and create more interesting games of your 
own. 
.
Playing the game 
You can download the executable to try out the game without having to 
compile it if you wish. Download it by clicking here - it is about 123k in 
length.Note that on faster PCs, it will be unplayably fast, so you will need to 
re-compile it with the pause_length constant set to a higher value. My PC is 
about 350MHz and it is OK.To move the snake, use 'a' for up, 'z' for down, 
'o' for left and 'p' for right. Again, there are constants you can change if you 
want to alter these settings. Press 'x' to exit the game at any time. 
The aim of the game is to collect the dots (food) and avoid the obstacles 
(crosses, borders, and the snake itself). As you collect food, the snake gets 
longer, so increasing your likelihood of crashing into yourself. When you 
have collected enough food, you progress onto the next level, where your 
snake gets longer, and the amount of food to collect to progress through the 
level gets larger.You get scored according to the length of the snake and the 
number of 'x' obstacles on the screen.The speed increases every 5 levels.You 
get a bonus when you complete the level of 1000, increasing by 1000 each 
level (e.g. complete level 5, you get a 5000 bonus).There is no concept of 
lives. Once you hit an obstacle, that's it, game over.Make sure you do not 
have the caps lock on, otherwise the keys will fail to respond
PROPOSED SYSTEM 
The following documentation is a project the “Name of the term paper allotted”. It is a 
detailed summary of all the drawbacks of the old system and how the new proposed 
system overcomes these shortcomings. The new system takes into account the various 
factors while designing a new system. It keeps into the account the Economical 
bandwidth available for the new system. The foremost thing that is taken care of is the 
Need and Requirements of the User. 
DESCRIPTION 
Before developing software we keep following things in mind that we can develop 
powerful and quality software 
PROBLEM STATEMENT 
o Problem statement was to design a module: 
o Which is user friendly 
o Which will restrict the user from accessing other user’s data. 
o Which will help user in viewing his data and privileges. 
o Which will help the administrator to handle all the changes. 
FUNCTIONS TO BE PROVIDED: 
The system will be user friendly and completely menu driven so that the users shall have 
no problem in using all options. 
o The system will be efficient and fast in response. 
o The system will be customized according to needs. 
o It is a game which can play by anyone 
o It is easy to use 
SYSTEM REQUIRMENTS 
Operating system: MS Windows XP or Windows Vista 
Language: C Language 
Processor: Pentium IV Processor 
RAM: 512 MB 
Hard disk: 5 GB
REQUIREMENT ANALYSIS 
This process is adopted when management of the system development, Personnel decide 
that the particular system needs improvement. The system development life cycle is the 
set of activities, carried out by the analyst, designers and users to develop and implement 
a system. The systems that are present in the nature follow common life cycle pattern. 
For example consider the raining system. Initially the rain falls into the river, river flows 
into sea, the sea water evaporates to form vapors, the vapors form clouds which again 
bring rain. Similarly consider a man made system initially a system is analyzed, designed 
and made operational by the efforts of system analysis. After successful operation or a 
number of users, the system becomes less and less effective by change in the 
environment. So these changes have to be incorporated in to the system by minor 
modifications. So the general activities from the life cycle of the system are given below: 
· Select ion and identification of the system to be studied 
· Preliminary study 
· Defining the system 
· Design and development of the system 
· Implementation of the system
SYSTEM DESIGN 
Then we began with the design phase of the system. System design is a solution, a “HOW 
TO” approach to the creation of a new system. It translates system requirements into 
ways by which they can be made operational. It is a translational from a user oriented 
document to a document oriented programmers. For that, it provides the understanding 
and procedural details necessary for the implementation. Here we use Flowchart to 
supplement the working of the new system. The system thus made should be reliable, 
durable and above all should have least possible maintenance costs. It should overcome 
all the drawbacks of the Old existing system and most important of all meet the user 
requirements. 
START 
enter the main menu of snake game 
Enter 
your 
choice 
? 
Enter name Play game quit 
Do you want to 
continue? 
STOP
SOURCE CODE 
#include <stdlib.h> 
#include <stdio.h> 
#include <conio.h> 
/* prototypes */ 
void draw_line(int col, int row); 
void show_score(); 
void add_segment(); 
void setup_level(); 
/* constants */ 
const int maxrow=15, maxcol=77; 
const int snake_start_col=33,snake_start_row=7; 
const char up_key='a', down_key='z', left_key='o', right_key='p'; 
const int pause_length=500000; 
/* global variables */ 
int score, snake_length, speed, obstacles, level, firstpress, high_score=0; 
char screen_grid[maxrow][maxcol]; 
char direction = right_key; 
struct snake_segment { 
int row,col; 
} snake[100]; 
void main() 
{ 
/* Variable declarations within main() only */ 
char keypress; 
do /* restart game loop */ 
{ 
obstacles=4; level=1; score=0; speed=14; 
randomize(); /* Ensure random seed initiated */ 
setup_level(); 
/* main loop */ 
do 
{ 
for (int i=0;i<(speed*pause_length);i++) int j=1+i; /*pause*/ 
/* If key has been hit, then check it is a direction key - if so, 
change direction */ 
if (kbhit()) 
{ 
keypress=(char)getch(); 
if((keypress==right_key)||(keypress==left_key)|| 
(keypress==up_key)||(keypress==down_key)) 
direction = keypress; 
} 
/* Add a segment to the end of the snake */ 
add_segment();
/* Blank last segment of snake */ 
gotoxy(snake[0].col,snake[0].row); 
cprintf(" "); 
/* ... and remove it from the array */ 
for (int i=1;i<=snake_length;i++) 
snake[i-1]=snake[i]; 
/* Display snake in yellow */ 
textcolor(YELLOW); 
for (int i=0;i<=snake_length;i++) 
{ 
gotoxy(snake[i].col,snake[i].row); 
cprintf("O"); 
} 
/* keeps cursor flashing in one place instead of following snake */ 
gotoxy(1,1); 
/* If first press on each level, pause until a key is pressed */ 
if (firstpress) { while(!kbhit()); firstpress = 0; } 
/* Collision detection - walls (bad!) */ 
if ((snake[snake_length-1].row>maxrow+1)||(snake[snake_length-1].row<=1)|| 
(snake[snake_length-1].col>maxcol+1)||(snake[snake_length-1].col<=1)|| 
/* Collision detection - obstacles (bad!) */ 
(screen_grid[snake[snake_length-1].row-2][snake[snake_length-1].col-2]=='x')) 
keypress='x'; /* i.e. exit loop - game over */ 
/* Collision detection - snake (bad!) */ 
for (int i=0;i<snake_length-1;i++) 
if ( (snake[snake_length-1].row)==(snake[i].row) && 
(snake[snake_length-1].col)==(snake[i].col)) 
{ 
keypress='x'; /* i.e. exit loop - game over */ 
break; /* no need to check any more segments */ 
} 
/* Collision detection - food (good!) */ 
if (screen_grid[snake[snake_length-1].row-2][snake[snake_length-1].col-2]=='.') 
{ 
/* increase score and length of snake */ 
score+=snake_length*obstacles; show_score(); snake_length++; add_segment(); 
/* if length of snake reaches certain size, onto next level */ 
if (snake_length==(level+3)*2) 
{ 
score+=level*1000; obstacles+=2; level++; /* add to obstacles */ 
if ((level%5==0)&&(speed>1)) speed--; /* increase speed every 5 levels */ 
setup_level(); /* display next level */ 
} 
} 
} while (keypress!='x');
/* game over message */ 
if (score > high_score) high_score = score; 
show_score(); 
gotoxy(30,6); textcolor(LIGHTRED); cprintf("G A M E O V E R"); 
gotoxy(30,9); textcolor(YELLOW); cprintf("Another Game 
y/n)? "); 
do keypress=getch(); while((keypress!='y')&&(keypress!='n')); 
} while (keypress=='y'); 
void setup_level() 
{ 
/* variables local to setup_level() */ 
int row,col; 
/* Set up global variables for new level */ 
snake_length=level+4; direction = right_key; 
firstpress = 1; 
/* Fill grid with blanks */ 
for(row=0;row<maxrow;row++) 
for(col=0;col<maxcol;col++) 
screen_grid[row][col]= ' '; 
/* Fill grid with Xs and food */ 
for(int i=0;i<obstacles*2;i++) 
{ 
row= rand()%maxrow; 
col= rand()%maxcol; 
if(i<obstacles) 
screen_grid[row][col]='x'; 
else 
screen_grid[row][col]='.'; 
} 
/* Create snake array of length snake_length */ 
for(int i=0;i<snake_length;i++) 
{ 
snake[i].row=snake_start_row; 
snake[i].col=snake_start_col+i; 
} 
/* Draw playing board */ 
draw_line(1,1); 
for(row=0;row<maxrow;row++) 
{ 
gotoxy(1,row+2); 
textcolor(LIGHTBLUE); cprintf("|"); 
textcolor(WHITE); 
for(col=0;col<maxcol;col++) 
cprintf("%c",screen_grid[row][col]); 
textcolor(LIGHTBLUE);
cprintf("|"); 
} 
draw_line(1,maxrow+2); 
show_score(); 
gotoxy(2,maxrow+5); 
textcolor(LIGHTRED); 
cprintf("~~ SNAKE GAME~~ Left: %c, Right: %c, Up: %c, Down: %c, Exit: x. Any 
key to start.", 
left_key,right_key,up_key,down_key); 
} 
void draw_line(int col, int row) 
{ 
gotoxy(col,row); textcolor(LIGHTBLUE); 
for (int col=0;col<maxcol+2;col++) cprintf("="); 
} 
void show_score() 
{ 
textcolor(LIGHTCYAN); 
gotoxy(2,maxrow+3); 
cprintf("Level: %05d",level); 
gotoxy(40,maxrow+3); 
textcolor(LIGHTGREEN); 
cprintf("Score: %05d",score); 
gotoxy(60,maxrow+3); 
textcolor(LIGHTMAGENTA); 
cprintf("High Score: %05d",high_score); 
} 
void add_segment() 
{ 
switch(direction) 
{ 
case(right_key): snake[snake_length].row=snake[snake_length-1].row; 
snake[snake_length].col=snake[snake_length-1].col+1; 
break; 
case(left_key) : snake[snake_length].row=snake[snake_length-1].row; 
snake[snake_length].col=snake[snake_length-1].col-1; 
break; 
case(up_key) : snake[snake_length].row=snake[snake_length-1].row-1; 
snake[snake_length].col=snake[snake_length-1].col; 
break; 
case(down_key) : snake[snake_length].row=snake[snake_length-1].row+1; 
snake[sn snake_length].col=snake[snake_length-1].col; 
} 
}
TESTING 
Testing is the major control measure used during software development. Its basic 
function is to detect errors in the software. During requirement analysis and design, the 
output is a document that is usually textual and no executable. After the coding phase, 
computer programs are available that can be executed for testing purpose. This implies 
that testing not only, has to uncover errors introduced during coding, but also errors 
introduced during previous phase. Thus the goal of testing is to uncover the requirements, 
design and coding errors in the programs. So after testing the outputs of my project are as 
follows: 
Main menu screen
If snake crosses the line then it terminate
FUTURE SCOPE OF THE PROJECT 
Our project will be able to implement in future after making some changes and 
modifications as we make our project at a 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

Contenu connexe

Tendances

Computer Organization And Architecture lab manual
Computer Organization And Architecture lab manualComputer Organization And Architecture lab manual
Computer Organization And Architecture lab manualNitesh Dubey
 
The complete srs documentation of our developed game.
The complete srs documentation of our developed game. The complete srs documentation of our developed game.
The complete srs documentation of our developed game. Isfand yar Khan
 
Ludo (snack-ladder) game project presentation
Ludo (snack-ladder) game project presentationLudo (snack-ladder) game project presentation
Ludo (snack-ladder) game project presentationZakaria Hossain
 
Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL Sharath Raj
 
Number Guessing Game
Number Guessing GameNumber Guessing Game
Number Guessing GameManish Kumar
 
Project report 393_395
Project report 393_395Project report 393_395
Project report 393_395VishruthKhare
 
quiz game project report.pdf
quiz game project report.pdfquiz game project report.pdf
quiz game project report.pdfzccindia
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cppAlamgir Hossain
 
Tic tac toe c++ project presentation
Tic tac toe c++ project presentationTic tac toe c++ project presentation
Tic tac toe c++ project presentationSaad Symbian
 
Game Development With Python and Pygame
Game Development With Python and PygameGame Development With Python and Pygame
Game Development With Python and PygameChariza Pladin
 
Breakout Ball project presentation
Breakout Ball project presentationBreakout Ball project presentation
Breakout Ball project presentationMdThohidulIslam3
 
Tic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max AlgorithmTic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max AlgorithmUjjawal Poudel
 
First game using c language
First game using c languageFirst game using c language
First game using c languageSaurabh Khetan
 

Tendances (20)

Computer Organization And Architecture lab manual
Computer Organization And Architecture lab manualComputer Organization And Architecture lab manual
Computer Organization And Architecture lab manual
 
Tic Tac Toe ppt
Tic Tac Toe pptTic Tac Toe ppt
Tic Tac Toe ppt
 
The complete srs documentation of our developed game.
The complete srs documentation of our developed game. The complete srs documentation of our developed game.
The complete srs documentation of our developed game.
 
Ludo (snack-ladder) game project presentation
Ludo (snack-ladder) game project presentationLudo (snack-ladder) game project presentation
Ludo (snack-ladder) game project presentation
 
Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL
 
Tic tac toe
Tic tac toeTic tac toe
Tic tac toe
 
Number Guessing Game
Number Guessing GameNumber Guessing Game
Number Guessing Game
 
Project report 393_395
Project report 393_395Project report 393_395
Project report 393_395
 
quiz game project report.pdf
quiz game project report.pdfquiz game project report.pdf
quiz game project report.pdf
 
Tic tac toe
Tic tac toeTic tac toe
Tic tac toe
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
 
Hangman game is interesting
Hangman game is interesting Hangman game is interesting
Hangman game is interesting
 
Tic Tac Toe
Tic Tac ToeTic Tac Toe
Tic Tac Toe
 
Tic tac toe
Tic tac toeTic tac toe
Tic tac toe
 
Tic tac toe c++ project presentation
Tic tac toe c++ project presentationTic tac toe c++ project presentation
Tic tac toe c++ project presentation
 
Game Development With Python and Pygame
Game Development With Python and PygameGame Development With Python and Pygame
Game Development With Python and Pygame
 
Breakout Ball project presentation
Breakout Ball project presentationBreakout Ball project presentation
Breakout Ball project presentation
 
Tic toc game presentation
Tic toc game presentationTic toc game presentation
Tic toc game presentation
 
Tic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max AlgorithmTic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max Algorithm
 
First game using c language
First game using c languageFirst game using c language
First game using c language
 

Similaire à Snake game implementation in c

ma project
ma projectma project
ma projectAisu
 
Scientific calculator in c
Scientific calculator in cScientific calculator in c
Scientific calculator in cUpendra Sengar
 
Book store automation system
Book store automation systemBook store automation system
Book store automation systemUpendra Sengar
 
Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Pritam Samanta
 
[Pandora 22] Ups and Down of Using Behaviour Trees in Unity to Model Villager...
[Pandora 22] Ups and Down of Using Behaviour Trees in Unity to Model Villager...[Pandora 22] Ups and Down of Using Behaviour Trees in Unity to Model Villager...
[Pandora 22] Ups and Down of Using Behaviour Trees in Unity to Model Villager...DataScienceConferenc1
 
Gdc09 Minigames
Gdc09 MinigamesGdc09 Minigames
Gdc09 MinigamesSusan Gold
 
Www.martin2k.co.uk vb6 tips_vb_41
Www.martin2k.co.uk vb6 tips_vb_41Www.martin2k.co.uk vb6 tips_vb_41
Www.martin2k.co.uk vb6 tips_vb_41naveedkz
 
Introduction to programming - class 2
Introduction to programming - class 2Introduction to programming - class 2
Introduction to programming - class 2Paul Brebner
 
Letselectronic.blogspot.com robotic arm based on atmega mcu controlled by win...
Letselectronic.blogspot.com robotic arm based on atmega mcu controlled by win...Letselectronic.blogspot.com robotic arm based on atmega mcu controlled by win...
Letselectronic.blogspot.com robotic arm based on atmega mcu controlled by win...Aymen Lachkhem
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Amr Alaa El Deen
 
Python week 2 2019 2020 for g10 by eng.osama ghandour
Python week 2 2019 2020 for g10 by eng.osama ghandourPython week 2 2019 2020 for g10 by eng.osama ghandour
Python week 2 2019 2020 for g10 by eng.osama ghandourOsama Ghandour Geris
 
Multiplayer Networking Game
Multiplayer Networking GameMultiplayer Networking Game
Multiplayer Networking GameTanmay Krishna
 
Operationalizing Clojure Confidently
Operationalizing Clojure ConfidentlyOperationalizing Clojure Confidently
Operationalizing Clojure ConfidentlyPrasanna Gautam
 
Game programming workshop
Game programming workshopGame programming workshop
Game programming workshopnarigadu
 

Similaire à Snake game implementation in c (20)

ma project
ma projectma project
ma project
 
Tictac
TictacTictac
Tictac
 
Tic tac toe game code
Tic tac toe game codeTic tac toe game code
Tic tac toe game code
 
Tic tac toe
Tic tac toeTic tac toe
Tic tac toe
 
Scientific calculator in c
Scientific calculator in cScientific calculator in c
Scientific calculator in c
 
Book store automation system
Book store automation systemBook store automation system
Book store automation system
 
ELAVARASAN.pdf
ELAVARASAN.pdfELAVARASAN.pdf
ELAVARASAN.pdf
 
Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game
 
[Pandora 22] Ups and Down of Using Behaviour Trees in Unity to Model Villager...
[Pandora 22] Ups and Down of Using Behaviour Trees in Unity to Model Villager...[Pandora 22] Ups and Down of Using Behaviour Trees in Unity to Model Villager...
[Pandora 22] Ups and Down of Using Behaviour Trees in Unity to Model Villager...
 
Gdc09 Minigames
Gdc09 MinigamesGdc09 Minigames
Gdc09 Minigames
 
HPC Examples
HPC ExamplesHPC Examples
HPC Examples
 
Www.martin2k.co.uk vb6 tips_vb_41
Www.martin2k.co.uk vb6 tips_vb_41Www.martin2k.co.uk vb6 tips_vb_41
Www.martin2k.co.uk vb6 tips_vb_41
 
Introduction to programming - class 2
Introduction to programming - class 2Introduction to programming - class 2
Introduction to programming - class 2
 
Letselectronic.blogspot.com robotic arm based on atmega mcu controlled by win...
Letselectronic.blogspot.com robotic arm based on atmega mcu controlled by win...Letselectronic.blogspot.com robotic arm based on atmega mcu controlled by win...
Letselectronic.blogspot.com robotic arm based on atmega mcu controlled by win...
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1
 
Python week 2 2019 2020 for g10 by eng.osama ghandour
Python week 2 2019 2020 for g10 by eng.osama ghandourPython week 2 2019 2020 for g10 by eng.osama ghandour
Python week 2 2019 2020 for g10 by eng.osama ghandour
 
Multiplayer Networking Game
Multiplayer Networking GameMultiplayer Networking Game
Multiplayer Networking Game
 
Operationalizing Clojure Confidently
Operationalizing Clojure ConfidentlyOperationalizing Clojure Confidently
Operationalizing Clojure Confidently
 
Game programming workshop
Game programming workshopGame programming workshop
Game programming workshop
 
ForLoops.pptx
ForLoops.pptxForLoops.pptx
ForLoops.pptx
 

Plus de Upendra Sengar

Shipping and Storage: A New Approach
Shipping and Storage: A New ApproachShipping and Storage: A New Approach
Shipping and Storage: A New ApproachUpendra Sengar
 
Sales and inventory management project report
Sales and inventory management project reportSales and inventory management project report
Sales and inventory management project reportUpendra Sengar
 
Data flow diagram for order system
Data flow diagram for order systemData flow diagram for order system
Data flow diagram for order systemUpendra Sengar
 
Medical store management system
Medical store management systemMedical store management system
Medical store management systemUpendra Sengar
 
Ticket window & automation system
Ticket window & automation systemTicket window & automation system
Ticket window & automation systemUpendra Sengar
 
Term paper of cse(211) avdhesh sharma c1801 a24 regd 10802037
Term paper of cse(211) avdhesh sharma c1801 a24 regd 10802037Term paper of cse(211) avdhesh sharma c1801 a24 regd 10802037
Term paper of cse(211) avdhesh sharma c1801 a24 regd 10802037Upendra Sengar
 
Telephone directory in c
Telephone directory in cTelephone directory in c
Telephone directory in cUpendra Sengar
 

Plus de Upendra Sengar (14)

Shipping and Storage: A New Approach
Shipping and Storage: A New ApproachShipping and Storage: A New Approach
Shipping and Storage: A New Approach
 
Sales and inventory management project report
Sales and inventory management project reportSales and inventory management project report
Sales and inventory management project report
 
Data flow diagram for order system
Data flow diagram for order systemData flow diagram for order system
Data flow diagram for order system
 
Data flow diagram
Data flow diagramData flow diagram
Data flow diagram
 
Medical store management system
Medical store management systemMedical store management system
Medical store management system
 
Analog term paper
Analog term paperAnalog term paper
Analog term paper
 
Photo-Elctric Effect
Photo-Elctric EffectPhoto-Elctric Effect
Photo-Elctric Effect
 
Ums in c
Ums in cUms in c
Ums in c
 
Ticket window & automation system
Ticket window & automation systemTicket window & automation system
Ticket window & automation system
 
Term paper of cse(211) avdhesh sharma c1801 a24 regd 10802037
Term paper of cse(211) avdhesh sharma c1801 a24 regd 10802037Term paper of cse(211) avdhesh sharma c1801 a24 regd 10802037
Term paper of cse(211) avdhesh sharma c1801 a24 regd 10802037
 
Telephone directory
Telephone directoryTelephone directory
Telephone directory
 
Student record
Student recordStudent record
Student record
 
Telephone directory in c
Telephone directory in cTelephone directory in c
Telephone directory in c
 
Bluetooth technology
Bluetooth technologyBluetooth technology
Bluetooth technology
 

Dernier

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Dernier (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

Snake game implementation in c

  • 1. OF Snake game Submitted in the partial fulfillment of the Degree of Bachelor of Technology (Integrated) In Computer Science and Engineering SUBMITTED BY:- GUIDED BY: Name Ankit&uttkarsh Miss Sukhdilpreet Kaur Regd. No 10801409, 10800775 Rollno (complete)R246B34&R246B35 SUBMITTED TO Department of Computer Science and Engineering Lovely Professional University Phagwara
  • 2. ACKNOWLEDGEMENT I take this opportunity to present my votes of thanks to all those guidepost who really acted as lightening pillars to enlighten our way throughout this project that has led to successful and satisfactory completion of this study. We are really grateful to our HOD Mr. Rohit Dhand for providing us with an opportunity to undertake this project in this university and providing us with all the facilities. We are highly thankful to Miss Sukhdilpreet Kaur for her active support, valuable time and advice, whole-hearted guidance, sincere cooperation and pains-taking involvement during the study and in completing the assignment of preparing the said project within the time stipulated. Lastly, We are thankful to all those, particularly the various friends , who have been instrumental in creating proper, healthy and conductive environment and including new and fresh innovative ideas for us during the project, their help, it would have been extremely difficult for us to prepare the project in a time bound framework. Name Ankit chopra uttkarsha singh 10800775 Regd.No10801409 R246B35 RollnoR246B34.
  • 3. TABLE OF CONTENTS 1. Introduction 2. Proposed system i. Description ii. System requirements 3. Requirement Analysis 4. System Design 5. Source code 6. Testing 7. Future scope of project
  • 4. INTRODUCTION The following is an example game written in C based on the game called 'snake' which has been around since the earliest days of home computing (I can remember writing a version of it for my ZX81), 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 relatively simple C program, and perhaps the basis by which to extend the principles and create more interesting games of your own. .
  • 5. Playing the game You can download the executable to try out the game without having to compile it if you wish. Download it by clicking here - it is about 123k in length.Note that on faster PCs, it will be unplayably fast, so you will need to re-compile it with the pause_length constant set to a higher value. My PC is about 350MHz and it is OK.To move the snake, use 'a' for up, 'z' for down, 'o' for left and 'p' for right. Again, there are constants you can change if you want to alter these settings. Press 'x' to exit the game at any time. The aim of the game is to collect the dots (food) and avoid the obstacles (crosses, borders, and the snake itself). As you collect food, the snake gets longer, so increasing your likelihood of crashing into yourself. When you have collected enough food, you progress onto the next level, where your snake gets longer, and the amount of food to collect to progress through the level gets larger.You get scored according to the length of the snake and the number of 'x' obstacles on the screen.The speed increases every 5 levels.You get a bonus when you complete the level of 1000, increasing by 1000 each level (e.g. complete level 5, you get a 5000 bonus).There is no concept of lives. Once you hit an obstacle, that's it, game over.Make sure you do not have the caps lock on, otherwise the keys will fail to respond
  • 6. PROPOSED SYSTEM The following documentation is a project the “Name of the term paper allotted”. It is a detailed summary of all the drawbacks of the old system and how the new proposed system overcomes these shortcomings. The new system takes into account the various factors while designing a new system. It keeps into the account the Economical bandwidth available for the new system. The foremost thing that is taken care of is the Need and Requirements of the User. DESCRIPTION Before developing software we keep following things in mind that we can develop powerful and quality software PROBLEM STATEMENT o Problem statement was to design a module: o Which is user friendly o Which will restrict the user from accessing other user’s data. o Which will help user in viewing his data and privileges. o Which will help the administrator to handle all the changes. FUNCTIONS TO BE PROVIDED: The system will be user friendly and completely menu driven so that the users shall have no problem in using all options. o The system will be efficient and fast in response. o The system will be customized according to needs. o It is a game which can play by anyone o It is easy to use SYSTEM REQUIRMENTS Operating system: MS Windows XP or Windows Vista Language: C Language Processor: Pentium IV Processor RAM: 512 MB Hard disk: 5 GB
  • 7. REQUIREMENT ANALYSIS This process is adopted when management of the system development, Personnel decide that the particular system needs improvement. The system development life cycle is the set of activities, carried out by the analyst, designers and users to develop and implement a system. The systems that are present in the nature follow common life cycle pattern. For example consider the raining system. Initially the rain falls into the river, river flows into sea, the sea water evaporates to form vapors, the vapors form clouds which again bring rain. Similarly consider a man made system initially a system is analyzed, designed and made operational by the efforts of system analysis. After successful operation or a number of users, the system becomes less and less effective by change in the environment. So these changes have to be incorporated in to the system by minor modifications. So the general activities from the life cycle of the system are given below: · Select ion and identification of the system to be studied · Preliminary study · Defining the system · Design and development of the system · Implementation of the system
  • 8. SYSTEM DESIGN Then we began with the design phase of the system. System design is a solution, a “HOW TO” approach to the creation of a new system. It translates system requirements into ways by which they can be made operational. It is a translational from a user oriented document to a document oriented programmers. For that, it provides the understanding and procedural details necessary for the implementation. Here we use Flowchart to supplement the working of the new system. The system thus made should be reliable, durable and above all should have least possible maintenance costs. It should overcome all the drawbacks of the Old existing system and most important of all meet the user requirements. START enter the main menu of snake game Enter your choice ? Enter name Play game quit Do you want to continue? STOP
  • 9. SOURCE CODE #include <stdlib.h> #include <stdio.h> #include <conio.h> /* prototypes */ void draw_line(int col, int row); void show_score(); void add_segment(); void setup_level(); /* constants */ const int maxrow=15, maxcol=77; const int snake_start_col=33,snake_start_row=7; const char up_key='a', down_key='z', left_key='o', right_key='p'; const int pause_length=500000; /* global variables */ int score, snake_length, speed, obstacles, level, firstpress, high_score=0; char screen_grid[maxrow][maxcol]; char direction = right_key; struct snake_segment { int row,col; } snake[100]; void main() { /* Variable declarations within main() only */ char keypress; do /* restart game loop */ { obstacles=4; level=1; score=0; speed=14; randomize(); /* Ensure random seed initiated */ setup_level(); /* main loop */ do { for (int i=0;i<(speed*pause_length);i++) int j=1+i; /*pause*/ /* If key has been hit, then check it is a direction key - if so, change direction */ if (kbhit()) { keypress=(char)getch(); if((keypress==right_key)||(keypress==left_key)|| (keypress==up_key)||(keypress==down_key)) direction = keypress; } /* Add a segment to the end of the snake */ add_segment();
  • 10. /* Blank last segment of snake */ gotoxy(snake[0].col,snake[0].row); cprintf(" "); /* ... and remove it from the array */ for (int i=1;i<=snake_length;i++) snake[i-1]=snake[i]; /* Display snake in yellow */ textcolor(YELLOW); for (int i=0;i<=snake_length;i++) { gotoxy(snake[i].col,snake[i].row); cprintf("O"); } /* keeps cursor flashing in one place instead of following snake */ gotoxy(1,1); /* If first press on each level, pause until a key is pressed */ if (firstpress) { while(!kbhit()); firstpress = 0; } /* Collision detection - walls (bad!) */ if ((snake[snake_length-1].row>maxrow+1)||(snake[snake_length-1].row<=1)|| (snake[snake_length-1].col>maxcol+1)||(snake[snake_length-1].col<=1)|| /* Collision detection - obstacles (bad!) */ (screen_grid[snake[snake_length-1].row-2][snake[snake_length-1].col-2]=='x')) keypress='x'; /* i.e. exit loop - game over */ /* Collision detection - snake (bad!) */ for (int i=0;i<snake_length-1;i++) if ( (snake[snake_length-1].row)==(snake[i].row) && (snake[snake_length-1].col)==(snake[i].col)) { keypress='x'; /* i.e. exit loop - game over */ break; /* no need to check any more segments */ } /* Collision detection - food (good!) */ if (screen_grid[snake[snake_length-1].row-2][snake[snake_length-1].col-2]=='.') { /* increase score and length of snake */ score+=snake_length*obstacles; show_score(); snake_length++; add_segment(); /* if length of snake reaches certain size, onto next level */ if (snake_length==(level+3)*2) { score+=level*1000; obstacles+=2; level++; /* add to obstacles */ if ((level%5==0)&&(speed>1)) speed--; /* increase speed every 5 levels */ setup_level(); /* display next level */ } } } while (keypress!='x');
  • 11. /* game over message */ if (score > high_score) high_score = score; show_score(); gotoxy(30,6); textcolor(LIGHTRED); cprintf("G A M E O V E R"); gotoxy(30,9); textcolor(YELLOW); cprintf("Another Game y/n)? "); do keypress=getch(); while((keypress!='y')&&(keypress!='n')); } while (keypress=='y'); void setup_level() { /* variables local to setup_level() */ int row,col; /* Set up global variables for new level */ snake_length=level+4; direction = right_key; firstpress = 1; /* Fill grid with blanks */ for(row=0;row<maxrow;row++) for(col=0;col<maxcol;col++) screen_grid[row][col]= ' '; /* Fill grid with Xs and food */ for(int i=0;i<obstacles*2;i++) { row= rand()%maxrow; col= rand()%maxcol; if(i<obstacles) screen_grid[row][col]='x'; else screen_grid[row][col]='.'; } /* Create snake array of length snake_length */ for(int i=0;i<snake_length;i++) { snake[i].row=snake_start_row; snake[i].col=snake_start_col+i; } /* Draw playing board */ draw_line(1,1); for(row=0;row<maxrow;row++) { gotoxy(1,row+2); textcolor(LIGHTBLUE); cprintf("|"); textcolor(WHITE); for(col=0;col<maxcol;col++) cprintf("%c",screen_grid[row][col]); textcolor(LIGHTBLUE);
  • 12. cprintf("|"); } draw_line(1,maxrow+2); show_score(); gotoxy(2,maxrow+5); textcolor(LIGHTRED); cprintf("~~ SNAKE GAME~~ Left: %c, Right: %c, Up: %c, Down: %c, Exit: x. Any key to start.", left_key,right_key,up_key,down_key); } void draw_line(int col, int row) { gotoxy(col,row); textcolor(LIGHTBLUE); for (int col=0;col<maxcol+2;col++) cprintf("="); } void show_score() { textcolor(LIGHTCYAN); gotoxy(2,maxrow+3); cprintf("Level: %05d",level); gotoxy(40,maxrow+3); textcolor(LIGHTGREEN); cprintf("Score: %05d",score); gotoxy(60,maxrow+3); textcolor(LIGHTMAGENTA); cprintf("High Score: %05d",high_score); } void add_segment() { switch(direction) { case(right_key): snake[snake_length].row=snake[snake_length-1].row; snake[snake_length].col=snake[snake_length-1].col+1; break; case(left_key) : snake[snake_length].row=snake[snake_length-1].row; snake[snake_length].col=snake[snake_length-1].col-1; break; case(up_key) : snake[snake_length].row=snake[snake_length-1].row-1; snake[snake_length].col=snake[snake_length-1].col; break; case(down_key) : snake[snake_length].row=snake[snake_length-1].row+1; snake[sn snake_length].col=snake[snake_length-1].col; } }
  • 13. TESTING Testing is the major control measure used during software development. Its basic function is to detect errors in the software. During requirement analysis and design, the output is a document that is usually textual and no executable. After the coding phase, computer programs are available that can be executed for testing purpose. This implies that testing not only, has to uncover errors introduced during coding, but also errors introduced during previous phase. Thus the goal of testing is to uncover the requirements, design and coding errors in the programs. So after testing the outputs of my project are as follows: Main menu screen
  • 14. If snake crosses the line then it terminate
  • 15. FUTURE SCOPE OF THE PROJECT Our project will be able to implement in future after making some changes and modifications as we make our project at a 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