# include <stdio.h>
# include <graphics.h>
# include <stdlib.h>
# include <dos.h>
# include <conio.h>
int gdriver=DETECT,gmode,x1=0,y1=0,x2,y2,k=0,c,a,i=0;
int bufx[150],bufy[150],dist=7,delayspeed=100,d;
int rndx,rndy,tail=2,size,dash=0;
int life=5;
int choice;
void randomnumber(void);
void move(int a);
void statusbar(void);
void main()
{
// registerfarbgidriver(EGAVGA_driver_far);
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
size=tail;
cleardevice();
printf("Devlopped By IDEAL BERG");
printf("Enter the speed:: \n<1> for slow <2> for slower <3> for slowest\n<4> for normal\n<5> for fast <6> for faster <7> for fastest");
scanf("%d",&choice);
switch(choice)
{
case 1: delayspeed=250;break;
case 2: delayspeed=200;break;
case 3: delayspeed=160;break;
case 4: delayspeed=90;break;
case 5: delayspeed=60;break;
case 6: delayspeed=40;break;
case 7: delayspeed=20;break;
};
cleardevice();
randomnumber();
bar3d(rndx,rndy,rndx+dist,rndy+dist,0,0);
statusbar();
while((c=getch())!='\033')
{
if (c=='\115') a=1;
if (c=='\113') a=2;
if (c=='\120') a=3;
if (c=='\110') a=4;
dash=0;
move(a);
}
}
void move(int a)
{
void checkcollision(int x1,int y1);
void checkcapture(int x1,int y1);
while(!kbhit())
{
if (!dash)
{
k=k++%size;
i++;
setfillstyle(1,7);
bar3d(x1,y1,x1+dist,y1+dist,0,0);
if(i>=size) // Style start
{
setfillstyle(0,0);
setcolor(0);
bar3d(bufx[k],bufy[k],bufx[k]+dist,bufy[k]+dist,0,0);
bufx[k]=x1;
bufy[k]=y1;
setcolor(15);
checkcapture(x1,y1);
}
else
{
bufx[1]=x1;
bufy[1]=y1;
}
if(a==1) x1=x1+dist;
if(a==2) x1=x1-dist;
if(a==3) y1=y1+dist;
if(a==4) y1=y1-dist;
checkcollision(x1,y1);
setfillstyle(1,14);
bar3d(x1,y1,x1+dist,y1+dist,0,0);
sound(300);
delay(delayspeed);
nosound();
delay(delayspeed);
}
}
}
void checkcollision(int x1,int y1)
{
int i;
for(i=1;i<=size;i++) if((bufx[i]==x1)&&(bufy[i]==y1)) dash=1; if((x1<0)||(x1>=400)||(y1<0)||(y1>400)) dash=1;
if(dash)
{
if(--life<0) exit(0); sound(700); delay(300); nosound(); if(size>25) life++;size=tail;
cleardevice();
}
statusbar();
}
void checkcapture(int x1,int y1)
{
int i;
if((x1==rndx)&&(y1==rndy))
{
size++;
sound(500);
delay(100);
randomnumber();
}
setfillstyle(11,14);
bar3d(rndx,rndy,rndx+dist,rndy+dist,0,0);
}
void statusbar()
{
char s[10];
s[1]=life;
setcolor(15);
rectangle(0,0,400,400);
gotoxy(55,2);
printf("Life: %d size: %d",life,size);
gotoxy(55,5);
printf("Down: ");
putchar(31);
printf("\tUP");
putchar(30);
gotoxy(55,6);
printf("RIGHT :");
putchar(16);
printf("\tLEFT :");
putchar(17);
}
void randomnumber()
{
int i,j;
randomize();
i=random(10000)%40;
i=i*dist;
j=random(10000)%40;
j=j*dist;
rndx=i;
rndy=j;
}
Kerala IT companies - webdevelopment webhosting application development Cochin
can someone verify if its correct
ReplyDeleteits correct
ReplyDelete