#include<stdio.h>#include<stdlib.h>#include<string.h>#include<conio.h>int x =0, y =0;// save mapint map[10][10]={0};// map 1int map_1[10][10]={{0,0,1,1,1,0,0,0},{0,0,1,4,1,0,0,0},{0,0,1,0,1,1,1,1},{1,1,1,0,0,2,4,1},{1,4,2,2,0,1,1,1},{1,1,1,3,2,1,0,0},{0,0,0,1,4,1,0,0},{0,0,0,1,1,1,0,0}};// map 2int map_2[10][10]={{0,0,0,1,1,1,1,1,1,1},{0,0,1,1,0,0,1,0,3,1},{0,0,1,0,0,0,1,0,0,1},{0,0,1,2,0,2,0,2,0,1},{0,0,1,0,2,1,1,0,0,1},{1,1,1,0,2,0,1,0,1,1},{1,4,4,4,4,4,0,0,1,0},{1,1,1,1,1,1,1,1,1,0}};// win?intfinish();// move manvoidmove(int x1,int y1,int x2,int y2);// print mapintrender();// find manvoidfind();// choose map 1 or 2voidsetmap(int n);// helpvoidhelp(void);intmain(void){int n;char dir;char c;help();printf("Please choose (1 or 2, q to exit): ");while(scanf("%d",&n)){getchar();// n==0, exitif(n ==0){printf("game over\n");break;}system("cls");if(n ==1|| n ==2){setmap(n);// choose maprender();while((dir =getch())!=EOF){system("cls");find();switch(dir){case'w':move(x -1, y, x -2, y);break;case's':move(x +1, y, x +2, y);break;case'a':move(x, y -1, x, y -2);break;case'd':move(x, y +1, x, y +2);break;case'r':setmap(n);break;case'q':return0;}render();if(finish()){printf("You Win!\n");printf("Please choose (1 or 2, q to exit): ");break;}}}else{printf("Please try again.\n");printf("Please choose (1 or 2, q to exit): ");}}system("pause");return0;}voidhelp(void){printf("*************Weclome to the box game*************\n""*\t\t\t\t\t\t*\n""*\t-------------------------------\t\t*\n""*\t\tPowered By X\t\t\t*\n""*\t-------------------------------\t\t*\n""*\t\t\t\t\t\t*\n""*\t\t+ : man\t\t\t\t*\n""*\t\t$ : address\t\t\t*\n""*\t\t@ : box\t\t\t\t*\n""*\t\t\t\t\t\t*\n""*\t\thelp\t\t\t\t*\n""*\t\tmove : wasd\t\t\t*\n""*\t\texit : q\t\t\t*\n""*\t\trestart : r\t\t\t*\n""*************************************************\n");}voidmove(int x1,int y1,int x2,int y2){if(map[x][y]==3)// find man{// In front of the person is the box. The Box is on the spaceif(map[x1][y1]==2){// In front of the box is spaceif(map[x2][y2]==0){
map[x][y]=0;
map[x1][y1]=3;
map[x2][y2]=2;}// In front of the box is the positionelseif(map[x2][y2]==4){
map[x][y]=0;
map[x1][y1]=3;
map[x2][y2]=5;}}// In front of you is the box. The Box is in positionelseif(map[x1][y1]==5){// In front of the box is spaceif(map[x2][y2]==0){
map[x][y]=0;
map[x1][y1]=6;
map[x2][y2]=2;}// In front of the box is the positionelseif(map[x2][y2]==4){
map[x][y]=0;
map[x1][y1]=6;
map[x2][y2]=5;}}// Blank in front of the personif(map[x1][y1]==0){
map[x1][y1]=3;
map[x][y]=0;}elseif(map[x1][y1]==4){
map[x][y]=0;
map[x1][y1]=6;}}elseif(map[x][y]==6)// People in position{// Before the position is the box, the box is on the spaceif(map[x1][y1]==2){// Boxes are preceded by Spacesif(map[x2][y2]==0){
map[x][y]=4;
map[x1][y1]=3;
map[x2][y2]=2;}// In front of the box is the positionelseif(map[x2][y2]==4){
map[x][y]=4;
map[x1][y1]=3;
map[x2][y2]=5;}}// Before the position is the box, the box is in the positionelseif(map[x1][y1]==5){// Boxes are preceded by Spacesif(map[x2][y2]==0){
map[x][y]=4;
map[x1][y1]=6;
map[x2][y2]=2;}// In front of the box is the positionelseif(map[x2][y2]==4){
map[x][y]=4;
map[x1][y1]=6;
map[x2][y2]=5;}}// Position is in front of peopleif(map[x1][y1]==4){
map[x][y]=4;
map[x1][y1]=6;}// People are preceded by Spaceselseif(map[x1][y1]==0){
map[x][y]=4;
map[x1][y1]=3;}}}voidfind(void){for(x =0; x <10; x++){for(y =0; y <10; y++){if(map[x][y]==3|| map[x][y]==6){return;}}}}intrender(void){for(x =0; x <10; x++){for(y =0; y <10; y++){if(map[x][y]==1){printf("*");// The output frame}elseif(map[x][y]==3){printf("+");// Output character location}elseif(map[x][y]==2){printf("@");// Output box}elseif(map[x][y]==4){printf("$");// Output destination}elseif(map[x][y]==0){printf(" ");// Output space}elseif(map[x][y]==5){printf("@");// Output the icon after reaching the destination location}elseif(map[x][y]==6){printf("+");// People arrvice at the destination after the output character}}printf("\n");}return0;}voidsetmap(int n){if(n ==1){memcpy(map, map_1,sizeof(map_1));}elseif(n ==2){memcpy(map, map_2,sizeof(map_2));}}intfinish(){for(x =0; x <10; x++){for(y =0; y <10; y++){if(map[x][y]==2)return0;}}return1;}