资源描述:
《C语言推箱子代码.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include#includeinti,j,steps=0,gk=1;charcommand,t,m=0,n=0;intmap_1[8][11],map[8][11]={{0,0,0,0,0,0,0,0,0,0,0},{1,1,1,1,0,0,0,0,0,0,0},{1,0,0,1,1,1,1,1,0,0,0},{1,0,0,6,0,0,4,1,0,0,0},{1,3,0,2,0,0,4,1,0,0,0},{1,0,0,1,1,1,1,1,0,0,0},{1,1,1,1,0,0
2、,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0}};intmap_2[8][11]={{0,0,0,1,1,1,1,0,0,0,0},{0,0,0,1,4,0,1,0,0,0,0},{1,1,1,1,0,0,1,1,0,0,0},{1,0,0,0,3,2,0,1,0,0,0},{1,0,1,1,0,0,0,1,0,0,0},{1,0,6,0,0,0,0,1,1,0,0},{1,1,1,1,0,0,0,4,1,0,0},{0,0,0,1,1,1,1,1,1,0,0}};intmap_3[8][11
3、]={{0,0,0,1,1,1,1,0,0,0,0},{0,0,0,1,4,4,1,0,0,0,0},{1,1,1,1,0,0,1,1,0,0,0},{1,0,0,0,0,0,0,1,0,0,0},{1,0,0,0,0,0,0,1,1,0,0},{1,1,1,0,1,6,2,0,1,0,0},{0,0,1,0,0,3,0,0,1,0,0},{0,0,1,1,1,1,1,1,1,0,0}};typedefstructposition{intx;inty;}location;locationagg[3];//全部通过vo
4、idclearance(){if(map[agg[1].x][agg[1].y]==5&&map[agg[2].x+n][agg[2].y+m]==5&&gk==3){精选范本,供参考!printf("你赢了!");system("pause");exit(0);}}//判断是否通过voidcontrol_adopt(){if(map[agg[1].x][agg[1].y]==5&&map[agg[2].x+n][agg[2].y+m]==5){if(gk!=3){for(i=0;i<8;i++)for(j=0;
5、j<11;j++){map[i][j]=map_2[i][j];map_2[i][j]=map_3[i][j];map_1[i][j]=map[i][j];}gk++;}steps=0;}}//重新开始voidcontrol_reset(charreset_1){if(reset_1=='f'){for(i=0;i<8;i++)for(j=0;j<11;j++)map[i][j]=map_1[i][j];steps=0;}}//结束voidcontrol_end(charend_0){if(end_0=='t')ex
6、it(0);}//控制方向+箱子堵住陷阱voidcontrol_direction(chardirection_){精选范本,供参考!if(direction_=='d'
7、
8、direction_=='w'
9、
10、direction_=='a'
11、
12、direction_=='s'){if(direction_=='d')m=1;if(direction_=='a')m=-1;if(direction_=='w')n=-1;if(direction_=='s')n=1;if(agg[0].x+n==agg[1].x&&(agg
13、[0].y+m)==agg[1].y&&map[agg[1].x+n][agg[1].y+m]!=1&&map[agg[1].x][agg[1].y]!=5){if(map[agg[1].x+n][agg[1].y+m]==4){map[agg[1].x][agg[1].y]=0;map[agg[1].x+n][agg[1].y+m]=5;agg[1].y=agg[1].y+m;agg[1].x=agg[1].x+n;}else{t=map[agg[1].x+n][agg[1].y+m];map[agg[1].x+n
14、][agg[1].y+m]=map[agg[1].x][agg[1].y];map[agg[1].x][agg[1].y]=t;agg[1].y=agg[1].y+m;agg[1].x=agg[1].x+n;}}//第二个箱子的判断条件if(agg[0].x+n==agg[2].x&&(agg[0].y+m)==agg[2].y&&map[ag