- Snake Game In C Language Without Graphics
- Snake Game In C Language Mini Project For Engineers
- Snake Game In C Language
- Snake Game Code In C Language
- Snake And Ladder Game In C Language
- Snake Game In C Language Pdf
In this page, we are sharing the source code of a 'simple snake game' developed on C# programming language as a windows form application. Here are the most relevant keywords about this game: Graphics, Timer, Double Buffering, First Game, Game Loop.
You can download the source code of the snake game from here. Please download the project, and build it with Visual Studio to run the application.
Note that, the application is written in C# programming language, using old style Windows Form Applications as UI components. Try to use WPF (windows presentation foundation) for better development and maintainability experiences.
Snake Game In C Language Without Graphics
This game contains one white colored object which is under user control and runs over the screen, and we need to touch the target object, which is in red color with out touching the border lines. Simple Snake game. Is a Games and Graphics source code in C programming language. Snake game in C Om prakash kartik May 17, 2020. Snake game in C. Tic Tac Toe game program in C language; Alphabet puzzle game in C; Number puzzle game in C.
How to improve the game?
1. Level: Update timer1.Interval to be 20 smaller when the size of the snake reaches multiplicatives of 10.
In this tutorial, we will take a look at how to create a super fun classic snake game in visual studio using C# programming language. I still remember this game from my old NOKIA phones, this game has gone through lots of different iterations over the years but the game is still lots of fun.
2. Walls: Add 3-5 blue points that represent walls. When snake hit them, it is gameover.
3. Score: Eating a food should have an award. Actually, reaching the food faster should be rewarded. When a food appears, you can start countnig from 20 to 1 in each step and add the value to the score.
4. Bonus food: Sometimes you may create other colors of foods that have bonus snake size and points.
5. Scores: Save the best scores and create a Top 10 list.
Snake Game In C Language Mini Project For Engineers
Snake game in C language .I have simplified the program which you can easily understand(see the explanation part). The program for snake game is of 235 lines.In this game you have to direct snake towards its food which randomly appears on the screen more it will eat more it will grow.Using arrow keys you can direct it. Before reading following explanation please read the explanation of Cricket game, Puzzle Game and stop watch because many of the concepts such as scan codes ,kbhit() function ,how to generate random numbers , I have explained their.
SOURCE CODE
#include<stdlib.h>
int m,n,a;
void boundary();
int snake(int x[1500],int y[1500],char d[1500])
{
int i;
long score=(a-5)*100;
if(x[0]m&&y[0]n)
{
take:
gotoxy(m,n);
printf(' ');
m=rand()%71+3;
n=rand()%17+4;
for(i=0;i<a;i++)
if(x[i]m&&y[i]n)
goto take;
a++;
}
if(a>=1406)
{
gotoxy(30,12);
printf('Congratulation You Won The Game');
gotoxy(32,12);
printf('Your Score : %ld',score);
getch();
return 1;
}
gotoxy(m,n);
printf('%c',5);
for(i=0;i<a;i++)
{
gotoxy(x[i],y[i]);
printf('%c',d[i]);
}
gotoxy(x[i],y[i]);
printf(' ');
gotoxy(3,23);
printf(' Your Score : %ld',score);
for(i=1;i<a;i++)
if(x[0]x[i]&&y[0]y[i])
goto out;
if(x[0]<3||x[0]>75||y[0]<4||y[0]>21)
{
out:
gotoxy(34,10);
printf('GAME OVER');
gotoxy(32,12);
printf('Your Score : %ld',score);
delay(1000);
getch();
return 1;
}
return 0;
}
void boundary()
{
int i,ab=3,de=22,cd=2,dc=1;
gotoxy(35,2);
printf('SNAKE GAME');
gotoxy(2,1);
printf('%c',201);
gotoxy(76,1);
printf('%c',187);
gotoxy(2,25);
printf('%c',200);
gotoxy(76,25);
printf('%c',188);
for(i=0;i<=72;i++,ab++)
{
gotoxy(ab,dc);
printf('%c',205);
gotoxy(ab,dc+2);
printf('%c',205);
gotoxy(ab,dc+21);
printf('%c',205);
gotoxy(ab,dc+24);
printf('%c',205);
}
de=76,ab=2;
gotoxy(33,23);
printf('BkSp Pausett Esc Quit') ;
printf('n made by:mohammed ujjain wala');
for(i=0;i<23;i++,cd++)
{
gotoxy(ab,cd);
printf('%c',186);
gotoxy(de,cd);
printf('%c',186);
}
gotoxy(2,3);
printf('%c',204);
gotoxy(2,22);
printf('%c',204);
gotoxy(76,3);
printf('%c',185);
gotoxy(76,22);
printf('%c',185);
}
void main()
{
int i,key,set,max=1406,x[1500],y[1500],speed=200,select;
char d[1500];
randomize();
m=rand()%71+2;
n=rand()%17+2;
clrscr();
printf('nnnnnttt MOHAMMED UJJAIN WALAnntttt PRESENTS');
printf('nnnttttSNAKE GAME');
printf('nnnnpress any key to continue');
getch();
while(1)
{
phir:
clrscr();
printf('nntttSNAKE GAME');
printf('nnnt1.) STARTtttpress 1nnt2.) INSTRUCTIONSttpress 2nnt3.) SETTINGStttpress 3nnt4.) EXITtttpress 4 ');
scanf('%d',&select);
clrscr();
boundary();
switch(select)
{
case 1:
for(i=0;i<max;i++)
d[i]='*',x[i]=i+40,y[i]=10;
d[0]=2,key=75,a=5;
while(1)
{
if(kbhit())
{
key=getch();
if(!key)
key=getch();
}
switch(key)
{
case 75:
if(x[0]-1x[1])
goto same;
for(i=a;i>0;i--)
y[i]=y[i-1],x[i]=x[i-1];
x[0]-=1,set=1;
if(snake(x,y,d))
goto phir;
break;
case 77:
if(x[0]+1x[1])
goto same;
for(i=a;i>0;i--)
y[i]=y[i-1],x[i]=x[i-1];
x[0]++,set=2;
if(snake(x,y,d))
goto phir;
break;
case 72:
if(y[0]-1y[1])
goto same;
for(i=a;i>0;i--)
y[i]=y[i-1],x[i]=x[i-1];
y[0]--,set=3;
if(snake(x,y,d))
goto phir;
break;
case 80:
if(y[0]+1y[1])
goto same;
for(i=a;i>0;i--)
y[i]=y[i-1],x[i]=x[i-1];
y[0]++,set=4;
if(snake(x,y,d))
goto phir;
break;
case 27:
goto phir;
case 32:
snake(x,y,d);
gotoxy(30,12);
printf('press any key to continue...');
getch();
clrscr();
boundary();
default:
same:
printf('a');
if(set1)
key=75;
else if(set2)
key=77;
else if(set3)
key=72;
else
key=80;
break;
}
if(kbhit())
delay(40);
else
delay(speed);
}
case 2:
clrscr();
printf('ttttHOW TO PLAYnnOur snake is hungry and you have to direct it toward its food ,more the snake will eat more it will grow .Remember snake should not collide with walls or itself or game will be over.nUse arrow key to move the snake');
printf('nnnttt ****ENJOY THE GAME****nnn press any key to continue..............');
getch();
goto phir;
case 3:
clrscr();
printf('ttttSETTINGSnEnter the speed level (1-5): ');
spee:
scanf('%d',&speed);
if(speed5)
speed=100;
else if(speed4)
speed=200;
else if(speed2)
speed=400;
else if(speed1)
speed=500;
else if(speed3)
speed=300;
else
{
clrscr();
printf('ttttSETTINGSnPlease enter the no.between 1-5 :');
goto spee;
}
printf('nYour speed level has been setnpress any key to continue');
getch();
goto phir;
case 4:
exit(0);
}
}
}
OUTPUT
Snake Game In C Language
EXPLANATION
After removing all the exception handling cases and unnecessary things, simplified program is given below#include<stdlib.h>
int m,n,a=5;
void snake(int x[1500],int y[1500],char d[1500])
{
int i;
if(x[0]m&&y[0]n)
{
m=rand()%70+1;
n=rand()%20+1;
a++;
}
gotoxy(m,n);
printf('%c',5);
for(i=0;i<a;i++)
{
gotoxy(x[i],y[i]);
printf('%c',d[i]);
}
}
void main()
{
int i,key=75,x[1500],y[1500];
char d[1500];
randomize();
m=rand()%70+1;
n=rand()%20+1;
for(i=0;i<1400;i++)
d[i]='*',x[i]=i+40,y[i]=10;
d[0]=2;
while(1)
{
clrscr();
if(kbhit())
{
key=getch();
if(!key)
key=getch();
}
for(i=a;i>0;i--)
y[i]=y[i-1],x[i]=x[i-1];
if(key75)
x[0]-=1;
else if(key77)
x[0]++;
else if(key72)
y[0]--;
else if(key80)
y[0]++;
else
exit(0);
snake(x,y,d);
delay(200);
}
}
Snake Game Code In C Language
Is it simple, yes ?Ok than let us understand the program.Snake And Ladder Game In C Language
Snake Game In C Language Pdf
RELATED POST:-