#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<bios.h>
#include<conio.h>
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
#define SPACE 0x3920
#define ENTER 0x1c0d
#define BILI 30
#define JZ 4
#define JS 3
#define n 19
int box[13][16]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,
1,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,
1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,1,
1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,
1,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,
1,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,};
int step_x,step_y ;
int key ;
int flag=1 ;
void draw_box();
void draw_cicle(int x,int y,int color);
void judgewho(int x,int y);
void judgekey();
void draw_box()
{
int x1,x2,y1,y2 ;
setbkcolor(LIGHTBLUE);
setcolor(YELLOW);
for(x1=1,y1=1,y2=10;x1<=12;x1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI);
for(x1=1,y1=1,x2=12;y1<=10;y1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI);
for(x1=13,y1=5,y2=8;x1<=15;x1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI);
for(x1=12,y1=5,x2=15;y1<=8;y1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI);
for(x1=1,y1=10,y2=12;x1<=6;x1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI);
for(x1=1,y1=10,x2=6;y1<=12;y1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI);
for(x1=9,y1=10,y2=12;x1<=12;x1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI);
for(x1=9,y1=10,x2=12;y1<=12;y1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI);
setcolor(GREEN);
for(x1=(3+4)*30,y1=(5+3)*30,y2=(8+3)*30;x1<=(5+4)*30;x1++)
line(x1,y1,x1,y2);
for(x1=(7+4)*30,y1=(5+3)*30,y2=(8+3)*30;x1<=(9+4)*30;x1++)
line(x1,y1,x1,y2);
for(x1=(5+4)*30,y1=(5+3)*30,y2=(6+3)*30;x1<=(7+4)*30;x1++)
line(x1,y1,x1,y2);
}
void draw_circle(int x,int y,int color)
{
setcolor(color);
setlinestyle(SOLID_LINE,0,1);
x=(x+JZ)*BILI+15 ;
y=(y+JS)*BILI+15 ;
circle(x,y,12);
}
void judgekey()
{
int i ;
int j ;
int x1,x2,x3,x4;
switch(key)
{
case LEFT :
if(step_x-1<0)
break ;
else
{
for(i=step_x-1,j=step_y;i>=1;i--)
if(box[j][i]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i<1)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case RIGHT :
if(step_x+1>14)
break ;
else
{
for(i=step_x+1,j=step_y;i<=14;i++)
if(box[j][i]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i>14)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case DOWN :
if((step_y+1)>11)
break ;
else
{
for(i=step_x,j=step_y+1;j<=11;j++)
if(box[j][i]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j>11)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case UP :
if((step_y-1)<0)
break ;
else
{
for(i=step_x,j=step_y-1;j>=1;j--)
if(box[j][i]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j<1)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case SPACE:
j=step_x;i=step_y;
do
{ key=bioskey(1);
x1=box[i-1][j]||box[i-1][j+1];
x2=box[i][j+1]||box[i+1][j+1];
x3=box[i+1][j]||box[i+1][j-1];
x4=box[i][j-1]||box[i-1][j-1];
if(x1==1&&x2==0)
{ draw_circle(step_x,step_y,LIGHTBLUE);
judgewho(++step_x,step_y);
j++;
delay(50000);
}
else if(x2==1&&x3==0)
{ draw_circle(step_x,step_y,LIGHTBLUE);
judgewho(step_x,++step_y);
delay(50000);
i++;
}
else if(x3==1&&x4==0)
{ draw_circle(step_x,step_y,LIGHTBLUE);
judgewho(--step_x,step_y);
delay(50000);
j--;
}
else if(x4==1&&x1==0)
{ draw_circle(step_x,step_y,LIGHTBLUE);
judgewho(step_x,--step_y);
delay(50000);
i--;
}
else { draw_circle(step_x,step_y,LIGHTBLUE);
judgewho(step_x,--step_y);
delay(50000);
i--;
}
} while(key!=ENTER);
case ENTER :
cleardevice();
draw_box();
draw_circle(step_x,step_y,15);
break ;
}
}
void judgewho(int x,int y)
{
draw_circle(x,y,15);
}
void main()
{
int gdriver=VGA,gmode=VGAHI;
clrscr();
initgraph(&gdriver,&gmode,"c:\\tc");
/* setwritemode(XOR_PUT);*/
flag=1 ;
draw_box();
step_x=1 ;
step_y=1 ;
/*draw_circle(step_x,step_y,8); */
judgewho(step_x,step_y);
do
{
while(bioskey(1)==0);
key=bioskey(0);
judgekey();
}
while(key!=ESC);
closegraph();
}