0% found this document useful (0 votes)
41 views5 pages

Mini Project in C Snake Game

Snake Game project msbte

Uploaded by

rajkirdath369
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views5 pages

Mini Project in C Snake Game

Snake Game project msbte

Uploaded by

rajkirdath369
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Mini Project in C Snake Game

This 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 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.

The source code for Snake Game in C is complete and totally error-free. It is
compiled in Code::blocks using the gcc compiler. The code is about 550 lines; so
I haven’t displayed the source code here. You can directly download the source
code plus application file from the link below.

Functions used in Snake Game Project in C:


Many functions have been used in this Snake mini project. Here, I will just list
them below and describe the functions “gotoxy”, “GotoXY” and “delay” as they
are some of the most important functions used in this and many mini projects in
C.

void record()
void load()
void Delay(long double)
void Move()
void Food()
void Print()
void Bend()
int Score()
void Boarder()
void Down()
void Left()
void Up()
void Right()
void ExitGame()

void gotoxy (int x, int y) – You need to understand this function as it is one of
the most important one used in Snake Game mini project in C. This function
allows you to print text in any place of screen. Using this function in
Code::Blocks requires coding, but it can be directly used in Turbo C. Here is a
code for this function in Code::Blocks.

Code for gotoxy (Mini Project in C Snake Game)


C

1 COORD coord = {0, 0}; // sets coordinates to (0,0) as global variables


2 void gotoxy (int x, int y)
3{
4 coord.X = x; coord.Y = y; // X and Y are the coordinates
5 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
6}

Here, COORD coord= {0,0}; is a global variable. It sets the center of axis to the
top left corner of the screen.

void GotoXY (int x, int y) – Here is the code for this function in Code::Blocks.

Code for GotoXY (Mini Project in C Snake Game)


C
1
void GotoXY(int x, int y)
2
{
3
HANDLE a;
4
COORD b;
5
fflush(stdout);
6
b.X = x;
7
b.Y = y;
8
a = GetStdHandle(STD_OUTPUT_HANDLE);
9
SetConsoleCursorPosition(a,b);
1
}
0

void delay(long double) – This function delays the execution. It can be used
directly in Turbo C, but requires coding in Code::Blocks. The code is given below:

Code for delay (Mini Project in C Snake Game)


C

1 void Delay(long double k)


2{
3 Score();
4 long double i;
5 for(i=0; i<=(10000000); i++);
6}

This mini project in C Snake game gives users a total of three lives to play the
game. The life-count decreases as the snake hits the wall or its own body. In this
mini project, you can even pause the game in the middle by pressing any key,
and you can press any key again to continue.

Output Screenshots:
Snake Game-Play

Game Instructions
End Game Screen
To sum it up, this mini project on Snake game in C allows you to record the
player’s name and the corresponding score obtained. File handling has been
used for that purpose.

This mini project can definitely help you if you were looking for a reference
project or looking to create a C mini project game of your own. Submitting this
project with little or no modification at all is completely discouraged.

You might also like