Introduction: Game of Snake in C
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.
Step 1: 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:
Step 2: Welcome Page of the Game
using above select proper background and font.
welcome the user by showing game title
Step 3: Selecting the Level of Game
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.
Step 4: Algorithm
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
The direction of snake can be changed using kbhit() function .
when you press the character accordingly it will change the direction of the snake.
Step 5: Algorithm for Increasing Size of Snake and Increasing Score
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.
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.
Step 6: Game Over Condition:
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.
Step 7: Quit Page
Last step ask user if he wants to continue playing or not.