#include<graphics.h>
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<dos.h>
int h[10][10];
int x[10]={50,110,170,230,290,350,410,470,530,590};
int y[10]={60,100,140,180,220,260,300,340,380,420};
struct time *t;
int i,j,u=1;
void dh()
{
int s,d=0;
while(d<200)
{
for(s=10;s<16;s++)
{
setcolor(0);
circle(x[j],y[i],s);
setcolor(s);
circle(x[j],y[i],s+1);
}
setcolor(0);
circle(x[j],y[i],s);
d++;
}
setcolor(5);
circle(x[j],y[i],10);
}
void mglb()
{
int a,b;
i=1;j=1;
for(a=1;a<9;a++)
for(b=1;b<9;b++)
h[a][b]=random(2)>0? 1:0;
h[1][1]=1;
h[8][8]=2;
}
void move(int f[])
{
int n=1,m;
while(f[n]!=0 && n<1000 && !bioskey(1) && h[1][1]!=5)
{
gettime(t);
gotoxy(1,2);
printf("%02d:%02d:%02d",t->ti_hour,t->ti_min,t->ti_sec);
sleep(1);
setcolor(0);
circle(x[j],y[i],10);
setcolor(1);
if(f[n]%2)
{
i=i-f[n]+2;
circle(x[j],y[i],10);
}
else
{
j=j-f[n]+3;
circle(x[j],y[i],10);
}
n++;
}
if(h[i][j]==2)
{
dh();
gotoxy(35,2);
gotoxy(33,2);
printf("Press 'F' To Next Map");
}
bioskey(0);
}
void scmg(int c,int d)
{
int a,b;
gotoxy(33,2);
printf(" ");
gotoxy(37,2);
printf("Ready!");
sleep(1);
gotoxy(37,2);
printf("Go!!!");
j=c,i=d;
for(a=0;a<10;a++)
for(b=0;b<10;b++)
{
setcolor(h[b][a]+11);
rectangle(x[a]-28,y[b]-18,x[a]+28,y[b]+18);
setcolor(0);
circle(x[a],y[b],10);
}
setcolor(1);
circle(x[c],y[d],10);
}
void mgfb(int s[][10])
{
int a,b;
for(a=0;a<10;a++)
for(b=0;b<10;b++)
s[a][b]=h[a][b];
}
void findway(int s[][10],int f[],int i,int j)
{
int m=1,k=1;
while(h[i][j]!=2 && k<999 && k!=0)
{
if(s[i+1][j]!=0 && f[k-1]!=3 && m<2)
{f[k]=1;i++;k++;m=1;s[i][j]=0;}
else if(s[i][j+1]!=0 && f[k-1]!=4 && m<3)
{f[k]=2;j++;k++;m=1;s[i][j]=0;}
else if(s[i-1][j]!=0 && f[k-1]!=1 && m<4)
{f[k]=3;i--;k++;m=1;s[i][j]=0;}
else if(s[i][j-1]!=0 && f[k-1]!=2 && m<5)
{f[k]=4;j--;k++;m=1;s[i][j]=0;}
else
{
k--;
if(f[k]%2)
i=i+f[k]-2;
else
j=j+f[k]-3;
m=f[k]+1;
}
}
if(k==0)
{
h[1][1]=5;
u=1;
}
f[k]=0;
}
void mu()
{
if(i!=0 && h[i-1][j]!=0)
{
setcolor(0);
circle(x[j],y[i],10);
i--;
setcolor(1);
circle(x[j],y[i],10);
}
if(h[i][j]==2)
{
dh();
gotoxy(35,2);
printf("Great!YouGotIt!");
sleep(1);
gotoxy(33,2);
printf("Press 'F' To Next Map");
}
}
void md()
{
if(i!=0 && h[i+1][j]!=0)
{
setcolor(0);
circle(x[j],y[i],10);
i++;
setcolor(1);
circle(x[j],y[i],10);
}
if(h[i][j]==2)
{
dh();
gotoxy(35,2);
printf("Great!YouGotIt!");
sleep(1);
gotoxy(33,2);
printf("Press 'F' To Next Map");
}
}
void ml()
{
if(j!=0 && h[i][j-1]!=0)
{
setcolor(0);
circle(x[j],y[i],10);
j--;
setcolor(1);
circle(x[j],y[i],10);
}
if(h[i][j]==2)
{
dh();
gotoxy(35,2);
printf("Great!YouGotIt!");
sleep(1);
gotoxy(33,2);
printf("Press 'F' To Next Map");
}
}
void mr()
{
if(i!=0 && h[i][j+1]!=0)
{
setcolor(0);
circle(x[j],y[i],10);
j++;
setcolor(1);
circle(x[j],y[i],10);
}
if(h[i][j]==2)
{
dh();
gotoxy(35,2);
printf("Great!YouGotIt!");
sleep(1);
gotoxy(33,2);
printf("Press 'F' To Next Map");
}
}
main()
{
int g=DETECT,h=VGA;
int s[10][10];
int f[1000];
int m;
initgraph(&g,&h,"");
randomize();
i=1,j=1;
while(u)
{
u=0;
mglb();
mgfb(s);
findway(s,f,i,j);
}
u=1;
scmg(1,1);
while(!bioskey(1))
{
gettime(t);
gotoxy(1,2);
printf("%02d:%02d:%02d",t->ti_hour,t->ti_min,t->ti_sec);
m=bioskey(0);
if(m==0x4B00 || m==7777)
ml();
else if(m==0x5000 || m==8051)
md();
else if(m==0x4D00 || m==8292)
mr();
else if(m==0x4800 || m==4471)
mu();
else if(m==4978)
{
mgfb(s);
findway(s,f,i,j);
move(f);
}
else if(m==8550)
{
while(u)
{
u=0;
mglb();
mgfb(s);
findway(s,f,i,j);
}
u=1;
scmg(1,1);
}
else if(m==0x011b)
{
closegraph();
exit(0);
}
}
}