level 2
zfy0422
楼主
/*地图编辑器*//*本程序可以画迷宫地图,并自动生成0,1代码保存在一个文件里*//*使用方法:按上下左右键可以控制物体的移动,按下空格键可以画方块,再按空格键可擦去方块*//*本程序存在一些问题,因为定义的数组不是很大,也没有考虑再数组外的情况,所以最好不要移出范围内*/#include
#include
#include
#include
#include
#define LEFT 120
#define TOP 40#
define RIGHT 520
#define BOTTOM 440#
define BIG 20#define SMALL 20int a[20][20];void drawcake(int x,int y)/*划方块*/{setfillstyle(SOLID_FILL,BLUE);bar(LEFT+1+x*SMALL,TOP+1+y*SMALL,RIGHT-1-19*SMALL+x*SMALL,BOTTOM-1-19*SMALL+y*SMALL);}void undrawcake(int x,int y)/*擦去方块*/{setfillstyle(SOLID_FILL,BLACK);bar(LEFT+1+x*SMALL,TOP+1+y*SMALL,RIGHT-1-19*SMALL+x*SMALL,BOTTOM-1-19*SMALL+y*SMALL);}main(){int gr=DETECT,gm,i,j,x=1,y=1,ch;FILE *fp;float f;initgraph(&gr,&gm,"");cleardevice();setbkcolor(0);fp=fopen("迷宫地图.txt","w");printf(" 地图编辑器");for(i=0;i<20;i++){drawcake(i,0); a[i][0]=1;drawcake(i,19);a[i][19]=1;drawcake(0,i); a[0][i]=1;drawcake(19,i);a[19][i]=1;}drawcake(x,y);do{ch=bioskey(0);switch(ch){case 19200:{if(a[x][y]==0)undrawcake(x,y);else ;x--;drawcake(x,y);break;}case 19712:{if(a[x][y]==0)undrawcake(x,y);else ;x++;drawcake(x,y);break;}case 18432:{if(a[x][y]==0)undrawcake(x,y);else ;y--;drawcake(x,y);break;}case 20480:{if(a[x][y]==0)undrawcake(x,y);else ;y++;drawcake(x,y);break;}case 14624:if(a[x][y]==0){drawcake(x,y);a[x][y]=1;}else{undrawcake(x,y);a[x][y]=0;}}}while(ch!=283);cleardevice();fp=fopen("迷宫地图.txt","w");for(x=0;x<20;x++){for(y=0;y<20;y++)fprintf(fp,"%d,",a[y][x]);fprintf(fp,"\n");}fclose(fp);getch();}/*本程序所有权归计算机网络安全研究协会*//*柳云飞 2004-11-5*/
2004年11月05日 08点11分
1
#include
#include
#include
#include
#define LEFT 120
#define TOP 40#
define RIGHT 520
#define BOTTOM 440#
define BIG 20#define SMALL 20int a[20][20];void drawcake(int x,int y)/*划方块*/{setfillstyle(SOLID_FILL,BLUE);bar(LEFT+1+x*SMALL,TOP+1+y*SMALL,RIGHT-1-19*SMALL+x*SMALL,BOTTOM-1-19*SMALL+y*SMALL);}void undrawcake(int x,int y)/*擦去方块*/{setfillstyle(SOLID_FILL,BLACK);bar(LEFT+1+x*SMALL,TOP+1+y*SMALL,RIGHT-1-19*SMALL+x*SMALL,BOTTOM-1-19*SMALL+y*SMALL);}main(){int gr=DETECT,gm,i,j,x=1,y=1,ch;FILE *fp;float f;initgraph(&gr,&gm,"");cleardevice();setbkcolor(0);fp=fopen("迷宫地图.txt","w");printf(" 地图编辑器");for(i=0;i<20;i++){drawcake(i,0); a[i][0]=1;drawcake(i,19);a[i][19]=1;drawcake(0,i); a[0][i]=1;drawcake(19,i);a[19][i]=1;}drawcake(x,y);do{ch=bioskey(0);switch(ch){case 19200:{if(a[x][y]==0)undrawcake(x,y);else ;x--;drawcake(x,y);break;}case 19712:{if(a[x][y]==0)undrawcake(x,y);else ;x++;drawcake(x,y);break;}case 18432:{if(a[x][y]==0)undrawcake(x,y);else ;y--;drawcake(x,y);break;}case 20480:{if(a[x][y]==0)undrawcake(x,y);else ;y++;drawcake(x,y);break;}case 14624:if(a[x][y]==0){drawcake(x,y);a[x][y]=1;}else{undrawcake(x,y);a[x][y]=0;}}}while(ch!=283);cleardevice();fp=fopen("迷宫地图.txt","w");for(x=0;x<20;x++){for(y=0;y<20;y++)fprintf(fp,"%d,",a[y][x]);fprintf(fp,"\n");}fclose(fp);getch();}/*本程序所有权归计算机网络安全研究协会*//*柳云飞 2004-11-5*/