📄 12-3.c
字号:
/*12_3.c*/
#include"12_1.c"
#include"12_2.c"
void inse(postype *st,postype *en); /*从键盘上输入迷宫进、出口位置;*/
int tdpath(selemtype *se); /*栈元素代表的位置着色;*/
void picture(mazetype lmaze[20][20]); /*图形方式在屏幕上画出迷宫;*/
void arrycop(mazetype from[20][20],mazetype to[20][20]); /*拷贝数组;*/
int getdataxy(int,int,postype *data,char *ch); /*在屏幕上给定位置输入;*/
void main()
{
mazetype mae,mazeb[20][20];
postype start,end;
selemtype e;
int flage=0;
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
arrycop(maze,mazeb);
do{
if(flage!=0)
{
arrycop(mazeb,maze);
destroystack(&s);
}
picture(maze);
inse(&start,&end);
if(mazepath(mae,start,end)==TRUE) stacktraver(s,tdpath);
else outtextxy(10,35,"maze is a problem!");
flage=1;
}while(getch()!=27);
destroystack(&s);
closegraph();
}
void picture(mazetype lmaze[20][20])
{
int i,j;
int color;
setbkcolor(BLACK);
for(i=0;i<10;i++)
for(j=0;j<10;j++)
{
if(lmaze[i][j].td==-1)
{
color=MAGENTA;
setfillstyle(1,color);
bar(100+j*20+K,100+i*20,118+j*20+K,118+i*20);
}
else
{
color=YELLOW;
setfillstyle(1,color);
bar(100+j*20+K,100+i*20,118+j*20+K,118+i*20);
}
}
}
void inse(postype *st,postype *en)
{
setcolor(GREEN);
setfillstyle(0,BLACK);
bar(10,5,200,45);
while(!getdataxy(10,5,st,"input start:"))
{
bar(10,20,200,30);
outtextxy(10,20,"data is error.");
}
while(!getdataxy(10,20,en,"input end:"))
{
bar(10,35,200,45);
outtextxy(10,35,"data is error.");
}
bar(10,35,200,45);
}
int getdataxy(int colum,int row,postype *data,char *ch)
{
int i=0,j=0;
char chx[20],*chy;
bar(colum,row,200,row+15);
outtextxy(colum,row,ch);
while((chx[i]=getch())!=13)
{
if(chx[i]>=48&&chx[i]<=57||chx[i]==44)
{
chx[++i]='\0';
outtextxy(110+7*j,row,&chx[i-1]);j++;
if(chx[i-1]==44) {chx[i-1]='\0';chy=&chx[i];}
}
}
chx[i]='\0';
if(chx[0]=='\0') return(0);
(*data).x=atoi(chx);(*data).y=atoi(chy);
if(maze[(*data).x][(*data).y].td==1) return(1);
else return(0);
}
int tdpath(selemtype *se)
{
int x,y;
x=se->seat.x;y=se->seat.y;
maze[x][y].td=0;
setcolor(BLUE);
setfillstyle(1,BLUE);
pieslice(100+20*y+9+K,100+20*x+9,30,330,8);
delay(100);
pieslice(100+20*y+9+K,100+20*x+9,0,360,8);
delay(200);
setcolor(YELLOW);
setfillstyle(1,YELLOW);
pieslice(100+20*y+9+K,100+20*x+9,0,360,8);
setcolor(MAGENTA);
setfillstyle(1,RED);
pieslice(100+20*y+9+K,100+20*x+9,0,360,4);
return 0;
}
void arrycop(mazetype from[20][20],mazetype to[20][20])
{
int i,j;
for(i=0;i<20;i++)
for(j=0;j<20;j++)
to[i][j]=from[i][j];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -