50% found this document useful (2 votes)
6K views

Snake Game in C Without Graphics

its here how to make snake game without graphics through c language. here is full game made main working of snake game you can see in play function if you know something in c language check this out this is the simple prgramme you can ever see its here...

Uploaded by

Shri Ram Choubey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
6K views

Snake Game in C Without Graphics

its here how to make snake game without graphics through c language. here is full game made main working of snake game you can see in play function if you know something in c language check this out this is the simple prgramme you can ever see its here...

Uploaded by

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

#include<stdio.

h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
void main()
{
int i,choice,set,s,color=15,a=100,sp,au,ty,pr,op,op2;
char c,z='#';
FILE *fp;
xy:
textcolor(15);
clrscr();
fp=fopen("snake.dat","r");
while(1)
{
c=fgetc(fp);
if(c==EOF)
break;
printf("%c",c);
}
fclose(fp);
printf("\nyour choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
play(color,a,au,z);
goto xy;
case 2:
setting();
printf("\n\n\n\t\t\tEnter Choice\n\t\t\t");
fflush(stdin);
scanf("%d",&s);
if(s==1)
{
clrscr();
printf("\n\n\n\n\n\n\t\t\t1.Snake Color\n\n\t\t\t2.Snake Type\n\
n\n\n\n\t\t\tEnter Your Choice\n\t\t\t");
scanf("%d",&set);
if(set==2)
{
clrscr();
printf("\n\n\n\n\t\t\tSnake Type\n\n\t\t\t1. #\n\t\t\t2. *\n\t\t
\t3. '.'\n\t\t\t4. @\n\n\n\n\n\t\t\tEnter Your Choice\n\t\t\t");
scanf("%d",&ty);
z=(ty==1?'#':ty==2?'*':ty==3?'.':'@');
goto xy;
}
if(set==1)
{
clrscr();
printf("\t\t\tSelect Color\n\n\n\t\t\t");
for(i=1;i<15;i++)
{
textcolor(i);
cprintf("%d",i);
printf("\n\t\t\t");
}
}

printf("\n\n\n\n\n\t\t\tYour Choice:\n\t\t\t");
fflush(stdin);
scanf("%d",&color);
goto xy;
}
if(s==2)
{clrscr();
printf("\n\n\n\n\t\t\tAudio Setting\n\n\t\t\t1. On\n\t\t\t2. Off
\n\n\n\n\n\t\tEnter Your Choice\t\t\t");
scanf("%d",&au);
goto xy;
}
if(s==3)
{
clrscr();
printf("\n\n\n\n\t\t\tEnter Dificulty Level\n\n\t\t\t1. Easy\n\t
\t\t2. Medium\n\t\t\t3. Hard\n\n\n\n\t\t\t");
scanf("%d",&sp);
a=(sp==1?150:sp==2?100:50);
goto xy;
}
break;
case 3:
help();
printf("\n\n");
line();
printf("\t\t1. Main Menu \t 2. Exit\n");
line();
scanf("%d",&op);
if(op==1)
goto xy;
if (op==2)
exit(0);
break;
case 4:
about();
printf("\n\n\n\n\n\n\n");
line();
printf("\t\t1.Main Menu \t 2. Exit\n");
line();
scanf("%d",&op2);
if(op2==1)
goto xy;
if(op2==2)
exit(0);
break;
case 5:
exit(0);
break;
}
}
play(int color,int a,int au,char z)
{
int p=1,k,l,m=0,i,x=30,y=15,e=0,strlen,t[100],u[100],pr,scr=0;
char ch,c;
me:
clrscr();

k=rand()%79;
l=rand()%25;
strlen=7;
while(1)
{
for(i=0;i<strlen;i++)
{
textcolor(15);
cprintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
gotoxy(65,25);
cprintf("Score = %d",scr);
if(l==25)
l=23;
gotoxy(k,l);
textcolor(15);
cprintf("@");
if(x==81)
{x=1;}
else if(x==0)
{x=80;}
else if(y==24)
{y=1;}
else if(y==0)
{y=23;}
textcolor(color);
for(e=0;e<strlen-m;e++)
{

//snake printing

gotoxy(t[e],u[e]);
cprintf("%c",z);
}
gotoxy(x,y);
printf("%c",z);gotoxy(80,25);

//front char and cursor blin

k
for(e=0;e<strlen;e++)

//game over

{
if(x==t[e]&&y==u[e])
{over(scr);printf("\n\n\t\tWana play again(y/n) : ");
fflush(stdin);c=getch();if(c=='y')goto me;else return(0);}
}
t[i]=x;u[i]=y;
if(x==k&&y==l)
{if(au==1)

//new target

{printf("\a");}
fflush(stdin);
k=rand()%80;
l=rand()%24;
strlen++;
scr++;
m=1;
}
if(kbhit())
{
ch=getch();
if(ch==72&&p!=2)
{p=4;}
else if(ch==75&&p!=1)
{p=3;}
else if(ch==77&&p!=3)
{p=1;}
else if(ch==80&&p!=4)
{p=2;}
else if(ch==27)
{exit(0);}

//movement
//move up
//move left
//move right
// move down
// esc to exit

if(p==1)
x++;
else if(p==2)
y++;
else if(p==3)
x--;
else if (p==4)
y--;
delay(a);
clrscr();
}
m=0;
}}
over(int scr)
{
clrscr();
printf("\n\n\n\t\t\tgame over...\n\n\t\t\tScore : %d\n",scr);
return 0;
}
setting()
{
char c;
FILE *fp;
clrscr();

fp=fopen("setting.dat","r");
while(1)
{
c=fgetc(fp);
if(c==EOF)
break;
printf("%c",c);
}
fclose(fp);
return 0;
}
help()
{
FILE *fp;
char c;
clrscr();
fp=fopen("help.dat","r");
while(1)
{
c=fgetc(fp);
if(c==EOF)
break;
printf("%c",c);
}
fclose(fp);
return 0;
}
about()
{
FILE *fp;
char c;
clrscr();
fp=fopen("about.dat","r");
while(1)
{
c=fgetc(fp);
if(c==EOF)
break;
printf("%c",c);
}
fclose(fp);
return 0;
}
line()
{
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n
");
return 0;
}

You might also like