728x90 AdSpace

Trending

Mini project snake game in c


Necessary things to be known before going to details:-


Self-Referential Structure
A self referential structure is used to create data structures like linked list, queue, stacks ....
Syntax to define self referential structure :-
struct <struct_name>
{
<datatype>  <variable_name>;
<struct_name> <*pointer_name>;
};
The structure used in this version of snake game is:
struct snake1
{
 int x;
 int y;//x,y represents the co-ordinates of the screen
 int i;//i is used for direction
 struct snake1 *body;
};

A self referential structure is one of the data structures which points to another structure of the same type.In above example snake1 is self referential structure.
gotoxy() function
gotoxy() places the cursor at appropriate position on the screen.The parameters passed to gotoxy() are column number followed by row number,
gotoxy() function is available in conio.h library
demonstration of gotoxy() function:
#include<stdio.h>
#include<conio.h>
int main(){
       printf("text at 0,0");
       gotoxy(20,20);
       printf("text at 20,20");
return 0;
}
kbhit() function
kbhit() funtion is used to determine if a key is pressed or not.kbhit() function is available in conio.h library.
this funtion places a key role in the snake game. So be perfect.
'C' code snippet to demonstrate kbhit() function,
while(!kbhit())
{
//loop repeats continuously until user press any key
}

w'll provide source code as soon as possible.
Try this out:-
Instructions to be followed to run downloaded version of snake game:-
First download and install dos-box and snake game.
save the snake game .exe file in  c drive,
open dos-box and enter commands given below:-
>mount c c:/
>c:/
>HACH!@GAME.exe
 press enter...!


Hope u like it...! :)
stay connected ...!
follow us on facebook....!



Mini project snake game in c Reviewed by Unknown on 09:50 Rating: 5 Necessary things to be known before going to details:- Self referential structure. gotoxy() function. kbhit() function. ASCII code...

No comments: