Your Ad Here

Friday, October 10, 2008

Maze

A Maze solving game in Computer Graphics....

#include stdio.h
#include graphics.h
#include conio.h
#include dos.h
int c=360,a,b;
int set=5;
void maze();
void display();
void win();
void clos();
void main()
{
int a[2]={0};
int y=410,x=605;
int ch,i;
// int x=290,y=210;
initgraph(a,a+1,"c:\\tc\\bgi");
// display();

maze();

while(ch!=27)
{

while(!kbhit())
{
setcolor(4);
switch(ch)
{
case 75:
x=x-1;
circle(x,y,5);
setcolor(set);
for(i=0;i<5;i++)
circle(x,y,i);
break;

case 77:
x=x+1;
circle(x,y,5);
setcolor(set);
for(i=0;i<5;i++)
circle(x,y,i);

break;

case 72:
y=y-1;
circle(x,y,5);
setcolor(set);
for(i=0;i<5;i++)
circle(x,y,i);

break;

case 80:
y=y+1;
circle(x,y,5);
setcolor(set);
for(i=0;i<5;i++)
circle(x,y,i);
break;
}
setcolor(4);
circle(290,240,10);

setcolor(set);
for(i=0;i<10;i++)
circle(290,240,i);
set++;
if(set==15)
set=5;

if(getpixel(x+6,y)==3||getpixel(x-6,y)==3||getpixel(x,y+6)==3||getpixel(x,y-6)==3)
{
clos();
exit(1);
}
if(getpixel(x+6,y)==2||getpixel(x-6,y)==2||getpixel(x,y+6)==2||getpixel(x,y-6)==2)
{
clos();
exit(1);
}
if(x<295 && x>285 && y<245 && y>235)
win();

delay(25);
setcolor(0);
circle(x,y,5);




}
ch=getch();
}
getch();
}
//---------------------------------------------------------------------------//
void maze()
{
setcolor(GREEN);
line(20,20,20,420);
line(20,20,620,20);
line(620,20,620,400);
line(20,420,620,420);
setcolor(CYAN);
//--------------------------vertical----------------------------//
line(50,20,50,60);line(50,80,50,140);line(50,160,50,240);line(50,280,50,340);
line(80,40,80,80);line(80,100,80,120);line(80,180,80,200);line(80,220,80,240);line(80,260,80,380);
line(110,60,110,80);line(110,200,110,220);line(110,240,110,260);line(110,280,110,340);
line(140,80,140,100);line(140,180,140,240);line(140,300,140,320);
line(170,60,170,100);line(170,160,170,240);line(170,340,170,360);line(170,380,170,400);
line(200,40,200,80);line(200,200,200,240);
line(230,20,230,40);line(230,80,230,100);line(230,140,230,180);line(230,220,230,260);line(230,320,230,340);
line(260,40,260,60);line(260,100,260,120);line(260,220,260,280);line(260,340,260,360);line(260,380,260,400);
line(290,360,290,380);line(290,400,290,420);
line(320,60,320,80); line(320,160,320,180);line(320,220,320,240);line(320,340,320,400);
line(350,80,350,140);line(350,200,350,260);line(350,320,350,340);line(350,360,350,420);
line(380,40,380,80); line(380,100,380,140);line(380,180,380,280);line(380,340,380,400);
line(410,20,410,40);line(410,100,410,300);
line(440,100,440,120); line(440,140,440,180);line(440,240,440,320);line(440,380,440,400);
line(470,160,470,200);line(470,240,470,280);line(470,300,470,320);line(470,360,470,380);
line(500,140,500,180);line(500,200,500,220);line(500,300,500,360);
line(530,40,530,80);line(530,100,530,260);line(530,300,530,320);line(530,340,530,380);
line(560,20,560,40);line(560,80,560,240);line(560,280,560,320);line(560,340,560,400);
line(590,40,590,220); line(590,240,590,340);line(590,360,590,400);
//--------------------------------horizontal----------------------//
line(80,40,200,40);line(260,40,380,40);line(410,40,530,40);
line(110,60,170,60);line(200,60,290,60);line(320,60,350,60);line(380,60,500,60);line(560,60,590,60);
line(50,80,110,80);line(230,80,320,80);line(380,80,560,80);
line(80,100,140,100);line(170,100,230,100);line(260,100,350,100);line(470,100,530,100);
line(80,120,260,120);line(290,120,350,120);line(440,120,530,120);
line(50,140,320,140);line(350,140,380,140);line(440,140,500,140);
line(50,160,200,160);line(260,160,320,160);line(350,160,410,160);
line(80,180,140,180);line(170,180,380,180);line(410,180,440,180);line(500,180,530,180);
line(80,200,110,200);line(200,200,350,200);line(440,200,500,200);
line(230,220,320,220);line(410,220,500,220);line(590,220,620,220);
line(50,240,80,240);line(110,240,140,240);line(440,240,530,240);line(560,240,590,240);
line(50,260,110,260);line(140,260,230,260);line(260,260,350,260);line(500,260,560,260);
line(110,280,380,280);line(470,280,560,280);
line(140,300,410,300);line(470,300,500,300);
line(140,320,320,320);line(350,320,440,320);line(530,320,560,320);
line(50,340,80,340);line(170,340,230,340);line(260,340,320,340);line(380,340,410,340);line(440,340,500,340);line(530,340,590,340);
line(20,360,50,360);line(110,360,260,360);line(380,360,500,360);
line(50,380,170,380);line(200,380,290,380);line(410,380,440,380);line(470,380,530,380);
line(20,400,140,400);line(170,400,260,400);line(290,400,320,400);line(380,400,410,400);line(440,400,560,400);line(590,400,620,400);
setcolor(4);
circle(290,240,10);

settextstyle(4,HORIZ_DIR,5);
outtextxy(280,420,"Maze...");
}

void display()
{
b=410;
while(b>-20)
{

settextstyle(1,0,6);
setcolor(8);
outtextxy(0,b," ");
delay(5);
setcolor(2);
outtextxy(0,b,"_ .");

b--;


}
b=-30;
while(b<620)
{
settextstyle(1,0,6);
setcolor(8);
outtextxy(b,0," ");
delay(5);
setcolor(2);
outtextxy(b,0,"!");

b++;


}
b=-20;
while(b<400)
{

settextstyle(1,0,6);
setcolor(8);
outtextxy(600,b," ");
delay(5);
setcolor(2);
outtextxy(600,b,"._");

b++;


}
b=620;
while(b>0)
{

settextstyle(1,0,6);
setcolor(8);
outtextxy(b,400,"");
setcolor(2);
delay(5);
outtextxy(b,400,"i");
b--;

}
settextstyle(7,1,4);

setcolor(4);
outtextxy(15,50,"Project By AAKASH");


while(c>290)
{ delay(50);
arc(250,240,30,320,c-200);
settextstyle(1,0,6);

c--;
}
delay(300);
settextstyle(1,0,4);
setcolor(4);
outtextxy(390,140,"Red Chilies");
delay(300);
outtextxy(370,330,"Entertainment ");
delay(300);

settextstyle(3,0,6);
setcolor(6);
outtextxy(170,200,"atch Me If U Can");

delay(100);
settextstyle(3,0,5);
setcolor(5);
delay(300);
outtextxy(25,443,"******************************");

settextstyle(2,0,18);
setcolor(5);
outtextxy(625,3,"*");
// while(c>0)
//{
//delay(50);
//arc(250,240,30,320,c-200);
//settextstyle(1,0,6);
//c--;
//}

}
void win()
{
cleardevice();
settextstyle(4,0,8);
outtextxy(getmaxx()/2-230,getmaxy()/2-100,"YOU WIN.....");
getch();
exit(1);
}
void clos()
{
cleardevice();
setcolor(4);
settextstyle(4,0,8);
outtextxy(getmaxx()/2-230,getmaxy()/2-230,"GAME OVER");
getch();
}

No comments: