//
// main.c
// 迷宫 诊断
//
// Created by 王先强 on 15/8/13.
// Copyright (c) 2015年 王先强. All rights reserved.
//
#include <stdio.h>
/*
打印地图
*/
void printf_map(char map[6][6]){
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
printf("%c",map[i][j]);
}
printf("\n");
}
}
//控制人移动的
// void pp_move(char map[6][6],int x1,int y1,int x2,int y2){
//
// char temp;
// temp = map[x2][y2] ;
// map[x1][y1] = map[x2][y2];
// map[x2][y2] = temp;
//
// }
int main(int argc, const char * argv[]){
char map[6][6]={
{'#','#','#','#','#','#'},
{'#','0','#','#',' ',' '},
{'#',' ','#','#',' ','#'},
{'#',' ',' ','#',' ','#'},
{'#','#',' ',' ',' ','#'},
{'#','#','#','#','#','#'}
};
//第一个变量,地图,接受用户输入方向,小人位置
char dic;
//先打印一遍地图,确定小人位置
printf_map(map);
//提醒用户玩法,接受用户输入方向并保存
printf("请输入方向:\n");
//循环控制小人移动
char a = ' ',chk;
while (1) {
int x1 = 1,y1 = 1;
scanf("%c",&dic);
scanf("%c",&chk);
switch (dic) {
case 'w':
case 'W':
if (map[x1-1][y1] == a) {
char temp;
temp = map[x1][y1] ;
map[x1][y1] = map[x1-1][y1];
map[x1-1][y1] = temp;
x1--;
} break;
case 's':
case 'S':
if (map[x1+1][y1] ==a ) {
char temp;
temp = map[x1][y1] ;
map[x1][y1] = map[x1+1][y1];
map[x1+1][y1] = temp;
x1++;
} break;
case 'a':
case 'A':
if (map[x1][y1-1] ==a ) {
char temp;
temp = map[x1][y1] ;
map[x1][y1] = map[x1][y1-1];
map[x1][y1-1] = temp;
y1--;
}break;
case 'd':
case 'D':
if (map[x1][y1+1] ==a ) {
char temp;
temp = map[x1][y1] ;
map[x1][y1] = map[x1][y1+1];
map[x1][y1+1] = temp;
y1++;
} break;
case 'q':
case 'Q':
return 0;
break;
default:
break;
}
printf_map(map);
if(y1 == 5){
printf("你赢了!\n");
break;
}
}
//判断小人是否移动
//移动 上下左右 、不移动
//小人是不是走出来了
return 0;
}
|
|