1 #include2 //宏定义 maze[ROWS][COLS];行和列; 3 #define ROWS 7 4 #define COLS 6 5 //绘制迷宫(全局变量) 6 char maze[ROWS][COLS]= { 7 { '#','#','#','#','#','#'}, 8 { '#','0','#',' ',' ',' '}, 9 { '#',' ','#',' ','#','#'},10 { '#',' ','#',' ',' ','#'},11 { '#',' ',' ','#',' ','#'},12 { '#','#',' ',' ',' ','#'},13 { '#','#','#','#','#','#'}14 };15 //设置X,Y坐标(全局变量);16 int currentX=1,currentY=1;17 //移动后的XY坐标(全局变量);18 int nextX,nextY;19 //看下一步是否能走 int[x][y]==' ' ;20 char street = ' ';21 22 //初始化函数23 void printMaze();24 void moveToNextPosition();25 void calculateNextPosition(char direction);26 27 28 29 int main(int argc, const char * argv[]) {30 nextX = currentX;31 nextY = currentY;32 //屏幕打印出迷宫;33 printMaze();34 char direction;35 while (1) {36 printf("请移动人物,用键盘W/S/A/D(上下左右)操作\n");37 scanf("%c",&direction);38 calculateNextPosition(direction);39 moveToNextPosition();40 printMaze();41 if (currentX==ROWS-1||currentY==COLS-1){42 printf("通关了,呵呵!");43 break;44 }45 }46 return 0;47 }48 49 50 //打印地图51 void printMaze(){52 for(int i = 0;i