0% found this document useful (0 votes)
26 views

Mini Project

Uploaded by

priyanshu sagar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Mini Project

Uploaded by

priyanshu sagar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

A Project Report

Submitted
In Partial Fulfillment of the Requirements
For the Degree of
Bachelor of Technology (B. Tech)
By
Priyanshu Sagar
2002150100033
Under the Supervision of
Neetu Mam

Of

Department of Computer Science & Engineering


Sanskar College Of Engineering and Technology,
Ghaziabad
Session (2023-2024)
Sanskar College of Engineering and Technology, Ghaziabad
Uttar Pradesh

Department of Computer Science & Engineering

This is to certify that the dissertation entitled “Snake Game”


submitted by Priyanshu Sagar in partial fulfillment of the
requirement for the award of degree of Bachelor of Technology,
A.P.J Abdul Kalam Technical University, Lucknow is a record of bona-
fide work carried out by them under my guidance and supervision.
The result embodied in this thesis has not been submitted to any
other university or institution for the award of any degree or diploma.

Internal Guide: HEAD of Department


Neetu Mam Mr.Mahesh Sharma
Acknowledgment

I am honored to express my gratitude as I embark on the journey of


developing the "Snake Game" a project assigned to me by my
esteemed teacher, Neetu Mam. Prof.
guidance, constructive comments, and unwavering inspiration
have been invaluable in shaping my understanding and approach to
this project.
I extend heartfelt appreciation to Neetu Mam for his/her significant
contributions and support.

All the work put into creating this game is dedicated to my family,
particularly my dear dad and mom, who stood by me in every
situation, providing unwavering support even during times of
financial need. Their encouragement has been my driving force, and
I am grateful for their constant presence. Lastly, I extend my sincere
thanks to all the faculties of SGIT for their assistance and support
throughout this endeavor.

Student:
Priyanshu Sagar

[Professor's Signature]
Index

 Introduction
 Objective
 Implementation
 Code Implementation
 Dependencies
 Workflow
 Challenges faced
 Results
 Future Enhancements
 Conclusion
 References
INTRODUCTION

The game called "Snake" or "Snake Game" typically involve the player controlling a line
or snake, there is no official version of the game, so gameplay varies. The most
common version of the game involves the snake or line eating items which make it
longer, with the objective being to avoid running into a border or the snake itself for as
long as possible. The player loses when the snake either runs into a border or its own
body. Because of this, the game becomes more difficult as it goes on, due to the
growth of the snake.
OBJECTIVE
This Project in C language 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.

• The snake is represented with a 0(zero) symbol.


• The fruit is represented with an F symbol.
• The snake can move in any direction according to the user with the help of the
keyboard (W, A, S, D keys).
• When the snake eats a fruit the score will increase by 10 points.
• The fruit will generate automatically within the boundaries.
• Whenever the snake will touch the boundary the game is over.
SOFTWARE REQUIREMENT

• Operating System : WINDOWS 7/8/10/11


• Application Software : TURBO C++ 2.0
• Language : C (Computer Graphics)
HARDWARE REQUIREMENT

• Hard Disk : 32 GB
• RAM : 128 MB
• Processor : Any Pentium Version
SNAPSHOT
STEPS TO CREATE THIS GAME

 There will be four user-defined functions.


 Build a boundary within which the game will be played.
 The fruits are generated randomly.
 Then increase the score whenever the snake eats a fruit
THE USER-DEFINED FUNCTIONS CREATED IN THIS PROGRAM

• Draw(): This function creates the boundary in which the game will be played.
• Setup(): This function will set the position of the fruit within the boundary.
• Input(): This function will take the input from the keyboard.
• MakeLogic(): This function will set the movement of the snake.
BUILT-IN FUNCTIONS USED

• kbhit(): This function in C is used to determine if a key has been pressed or not. To
use this function in a program include the header file conio.h. If a key has been
pressed, then it returns a non-zero value otherwise it returns zero.
• rand(): The rand() function is declared in stdlib.h. It returns a random integer value
every time it is called.
SOURCE CODE

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int width = 20, height = 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=height/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++)
{
for(j=0;j<width;j++)
{
if(i==0||i==height-1||j==0||j==width-1)
{
printf("*");
}
else
{
if(i==x && j==y)
printf ("O");
else if(i==fruitX && j==fruitY)
printf("F");
else
{
int ch=0;
for(k=0;k<CountTail;k++)
{
if(i==tailX[k] && j==tailY[k])
{
printf("o");
ch=1;
}
}
if(ch==0)
printf(" ");
}
}
}
printf("\n");
}
printf("SCORE=%d",score);
}
void input()
{
if(kbhit())
{
switch(getch())
{
case 'a': //aswz
flag=1;
break;
case 'd':
flag=2;
break;
case 'w':
flag=3;
break;
case 's':
flag=4;
break;
case 'x':
gameOver =1;
break;
}
}
}
void MakeLogic()
{
int i;
int prevX=tailX[0];
int prevY=tailY[0];
int prev2X,prev2Y;
tailX[0]=x;
tailY[0]=y;
for(i=1;i<CountTail;i++)
{
prev2X=tailX[i];
prev2Y=tailY[i];
tailX[i]=prevX;
tailY[i]=prevY;
prevX=prev2X;
prevY=prev2Y;

}
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>height)
gameOver=1;
for(i=0;i<CountTail;i++)
{
if(x==tailX[i] && y==tailY[i])
gameOver=1;
}
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<10000;n++){

}
}
for(m=0;m<10000;m++){
for(n=0;n<10000;n++){

}
}
}
printf("\nPress Y to continue again: ");
scanf("%c",&c);
if(c=='y' || c=='Y')
goto label5;
return 0;
}
REFERENCE

https://www.youtube.com/watch?v=L23H0lJ_eXM
https://www.youtube.com/watch?v=cBvw4-a6VlA
https://www.youtube.com/watch?v=PZZwnV8m0oo
https://www.youtube.com/watch?v=zcoEDCe4WZc

https://www.youtube.com/watch?v=ON5ODiAAQE&list=TLPQMjUwMTIwMjLY5Pxv8T0wK
A&index=2
https://www.geeksforgeeks.org/snake-game-in-c/
https://www.slideshare.net/ashutoshkumarkumar/project-on-snake-game-in-c-
language

You might also like