#includestdio.h#includestdlib.hinti,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,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]={{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];//全部通过voidclearance(){if(map[agg[1].x][agg[1].y]==5&&map[agg[2].x+n][agg[2].y+m]==5&&gk==3){printf(你赢了!\n);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;i8;i++)for(j=0;j11;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;i8;i++)for(j=0;j11;j++)map[i][j]=map_1[i][j];steps=0;}}//结束voidcontrol_end(charend_0){if(end_0=='t')exit(0);}//控制方向+箱子堵住陷阱voidcontrol_direction(chardirection_){if(direction_=='d'||direction_=='w'||direction_=='a'||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[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][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[agg[2].x+n][agg[2].y+m]!=1&&map[agg[2].x][agg[2].y]!=5){if(map[agg[2].x+n][agg[2].y+m]==4){map[agg[2].x][agg[2].y]=0;map[agg[2].x+n][agg[2].y+m]=5;agg[2].y=agg[2].y+m;agg[2].x=agg[2].x+n;}else{t=map[agg[2].x+n][agg[2].y+m];map[agg[2].x+n][agg[2].y+m]=map[agg[2].x][agg[2].y];map[agg[2].x][agg[2].y]=t;agg[2].y=agg[2].y+m;agg[2].x=agg[2].x+n;}}if(map[agg[0].x+n][agg[0].y+m]==0){t=map[agg[0].x+n][agg[0].y+m];map[agg[0].x+n][agg[0].y+m]=map[agg[0].x][agg[0].y];map[agg[0].x][agg[0].y]=t;agg[0].y=agg[0].y+m;agg[0].x=agg[0].x+n;steps++;}m=0;n=0;}}//输出,寻找1,2,3voidcontrol_output(){printf(关卡%d:\n,gk);printf(步数:%d\n,steps);for(i=0;i8;i++){for(j=0;j11;j++){if(map[i][j]==1)printf(■);if(map[i][j]==0)printf();if(map[i][j]==2){printf(□);agg[1].x=i;agg[1].y=j;}if(map[i][j]==3){printf(⊙);agg[0].x=i;agg[0].y=j;}if(map[i][j]==4)printf(☆);if(map[i][j]==5)printf(★);if(map[i][j]==6){printf(□);agg[2].x=i;agg[2].y=j;}}printf(\n);}printf(w,a,s,d控制方向,t退出游戏,f重新开始!\n);}//输入指令voidinput_command(){while(1){scanf(%c,&command);if(command=='w'||command=='a'||command=='s'||command=='d'||command=='t'||command=='f')break;}}main(){for(i=0;i8;i++){for(j=0;j12;j++){map_1[i][j]=map[i][j];}}while(1){control_output();input_command();control_direction(command);control_reset(command);control_end(command);control_adopt();system(cls);clearance();}}