Game of Snake in C

by earnest vekariya in Circuits > Computers

27058 Views, 10 Favorites, 0 Comments

Game of Snake in C

s1.png

Snake game was popular in old mobile phones which can be very easily devolped using c program. To build this project you require basic understanding of c syntax. Example:for loop,while loop,etc.

With building this type of game project your programming skill will improve to great extend.

Learning Some Basic Syntax for Devolping Gui

You can add colour and you can print where you want to write

You need to learn basic syntax like:

1)gotoxy(x,y)

2)textcolour()

3)textbackground()

4)kbhit()

Welcome Page of the Game

s2.png

using above select proper background and font.

welcome the user by showing game title

Selecting the Level of Game

s3.png

After displaying the game title.

Do clear screen()

show the levels and ask user to select the level

save the level selected by user in variable and use it to increase the difficulty level of user.

Algorithm

s4.png

random function:

In c program there is a random function which is used to place the food at any point on the screen.

Thus,use this function to place food at any point on the screen

Moving snake in the screen:

As you can see snake is printed by printing ''*'' on the screen 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.

Algorithm for Increasing Size of Snake and Increasing Score

s5.png

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

From above image it can be clear that user score and size of snake is increased.

Game Over Condition:

s6.png

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.

Quit Page

s7.png
s8.png

Last step ask user if he wants to continue playing or not.

Vedio and C Code Link

WP 20170303 00 49 06 Pro