1、#include#include#include#include#include#includevoid step(void);#define xo 320#define yo 240float x=0,y=0,x0=0,y0=0,qq,rr,s205;int x1,y1,DX,DY,rp=0;int i1;char file100;void menu(void)printf(“n%50s“,“printf(“n%50s“,“printf(“n%50s“,“printf(“n%50s“,“printf(“n%50s“,“printf(“n%50s“,“printf(“n%50s“,“print
2、f(“nnnn“);printf(“nchoice(0-4):“);scanf(“%d“, return;void quit(void)closegraph();fcloseall();exit(0);void load(void)FILE*fp;char*name,filename30;int ii,endflag;filename0=28;printf(“Input filename:“);name=cgets(filename);printf(“n“);if(fp=fopen(name,“r“)=NULL)printf(“nFile not found!n“);elseendflag=0
3、;ii=1;while(!endflag)if(fgets(fileii,100,fp)=NULL)if (ferror(fp)!=0)printf(“Error in readingn“);if(feof(fp)!=0)printf(“-End-“);endflag=1;elseprintf(“%s“,fileii);delay(1000);ii+;fclose(fp);return;void compile(void) FILE *fp;char ch,*name;int endof_line=0,m,d,c=0,i=0,j=0,r=0,k,L,n;char filename100;fil
4、ename0=50;while(r=0)printf(“n Input filename:“);name=cgets(filename);if(fp=fopen(name,“r“)=NULL)printf(“n no fire!“);r=0;else r=1;while (ch != EOF)ch=fgetc(fp);if(ch=g)|(ch=G)ch=fgetc(fp);m=0; d=0;while(ch=0)if(y0=0)e=5;if (x00)e=2;if(x0=0)e=6;if (x0=0)xxx();a=a-1;if(b=0)y0=y0+1;yyy();b=b-1;if(e=2)i
5、f(a=0)x0=x0-1;xx1();a=a-1;if(b=0)y0=y0+1;yyy();b=b-1;if(e=3)if(a=0)x0=x0-1;xx1();a=a-1;if(b=0)y0=y0-1;yy1();b=b-1;if(e=4)if(a=0)x0=x0+1;xxx();a=a-1;if(b=0)y0=y0-1;yy1();b=b-1;if(e=5)x0=x0+1;xxx();a=a-1;if(e=6)y0=y0+1;yyy();b=b-1;if(e=7)x0=x0-1;xx1();a=a-1;if(e=8)y0=y0-1;yy1();b=b-1;draw(x0,y0,c,d);w
6、hile(!(a0) else e=1; if (x00) if (x0=0) e=6; else e=2; if (x0=0)x0=x0+1;xxx();if(e=2) p=p-y;x0=x0-1;xx1();if(e=3) p=p+y;x0=x0-1;xx1();if(e=4) p=p+y;x0=x0+1;xxx();else if(e=1) p=p+x;y0=y0+1;yyy();if(e=2) p=p-x;y0=y0+1;yyy();if(e=3) p=p-x;y0=y0-1;yy1();if(e=4) p=p+x;y0=y0-1;yy1();if(e=5) x0=x0+1;xxx()
7、;if(e=6) y0=y0+1;yyy();if(e=7) x0=x0-1;xx1();if(e=8) y0=y0-1;yy1();draw(x0,y0,a,b);x0=sh1+xo;y0=yo-sh2;void draw1(float aa,float bb,float cc,float dd)aa=aa+cc;bb=dd-bb;lineto(aa,bb);void g02(int h)float p=0,k,f=0;int a,b,e,c,d;x=sh1+xo;y=yo-sh2;a=x0;b=y0;c=x0+sh3;d=y0-sh4;x0=x-x0;y0=y-y0;if(x00)if(x
8、00) x0=(a-c);y0=(d-b);a=x0;b=y0;x=(x-c);y=(d-y);while(f=0)if(e=1)p=p-2*y0+1;y0=y0-1;yy1();f+;if(e=2)p=p+2*x0+1;x0=x0+1;xxx();f+;if(e=3)p=p+2*y0+1;y0=y0+1;yyy();f+;if(e=4)p=p-2*x0+1;x0=x0-1;xx1();f+;elseif(e=1)p=p+2*x0+1;x0=x0+1;xxx();f+;if(e=2)p=p+2*y0+1;y0=y0+1;yyy();f+;if(e=3)p=p-2*x0+1;x0=x0-1;xx
9、1();f+;if(e=4)p=p-2*y0+1;y0=y0-1;yy1();f+;draw1(x0,y0,c,d);x0=sh1+xo;y0=yo-sh2;void g03(int h)float p=0,k,f=0;int a,b,e,c=x0,d=y0;x=sh1+xo;y=yo-sh2;a=x0;b=y0;c=x0+sh3;d=y0-sh4;x0=x-x0;y0=y-y0;if(x00)e=2;if(x00)if(x00)x0=x0-1;xx1();f+;if(e=2) p=p-2*y0+1;y0=y0-1;yy1();f+;if(e=3) p=p+2*x0+1;x0=x0+1;xxx
10、();f+;if(e=4) p=p+2*y0+1;y0=y0+1;yyy();f+;else if(e=1) p=p+2*y0+1;y0=y0+1;yyy();f+;if(e=2) p=p-2*x0+1;x0=x0-1;xx1();f+;if(e=3)p=p-2*y0+1;y0=y0-1;yy1();f+;if(e=4)p=p+2*x0+1;x0=x0+1;xxx();f+;draw1(x0,y0,c,d);while (f150|y1=150)outtextxy(270,400,“out of scope!“);moveto(x0,y0);break;elsesetfillstyle(BLA
11、CK,BLACK);setcolor(BLACK);bar3d(200,391,429,410,0,0);setcolor(WHITE);moveto(x0,y0);y-;if(1160|x1=160)outtextxy(270,400,“out of scope!“);moveto(x0,y0);break;elsesetfillstyle(BLACK,BLACK);setcolor(BLACK);bar3d(200,391,429,410,0,0);setcolor(WHITE);moveto(x0,y0);x+;if(1x|1=x)elsex=1;stepx();outport(base
12、a,(DY+DX);x0+;lineto(x0,y0);x1+;break;case 0x4b00:if(x1(-160)|x1=(-160)outtextxy(270,400,“out of scope!“);moveto(x0,y0);break;elsesetfillstyle(BLACK,BLACK);setcolor(BLACK);bar3d(200,391,429,410,0,0);setcolor(WHITE);moveto(x0,y0);x-;if(1x|1=x)elsex=6;stepx();outport(basea,(DY+DX);x0-;lineto(x0,y0);x1
13、-;break;case 0x011b:outport(basea,0);fr=0;break; getch();closegraph();getch();return; void step(void)int gdriver=DETECT,gmode;initgraph(x0=320;y0=240;x1=0;y1=0;x=0;y=0;DX=0;DY=0;moveto (x0,y0);contrl();int disp() int gdriver=DETECT,gmode;initgraph(setbkcolor(BLUE);setcolor(WHITE);rectangle(10,10,630
14、,465);setcolor(WHITE);line(20,yo,620,yo);setcolor(WHITE);line(xo,20,xo,455);line(xo,20,xo-2,30);line(xo,20,xo+2,30);line(620,yo,610,yo+2);line(620,yo,610,yo-2);outtextxy(xo+5,yo-215,“y“);outtextxy(xo+295,yo+5,“x“);outtextxy(xo+5,yo+5,“0“);void run(void)int h,m;disp();setcolor(LIGHTGREEN);x=0;y=0;qq=
15、0;rr=0;outport(0x280,0);moveto(xo,yo);for(h=0;hrp;h+)if(sh0=0) g00(h);if(sh0=1) g01(h);if(sh0=2) g02(h);if(sh0=3) g03(h);for(h=0;h=rp;h+)for(m=0;m=20;m+)shm=0;getch();closegraph();return; main()int end=0;x0=xo;y0=yo;while(!end) menu();switch(i1)case 0:quit();break;case 1:load();break;case 2:compile();break;case 3:compile();run();break;case 4:step();break;default:end=1;return;