//
// main.c
// 迷宫游戏
//
// Created by niaoren on 15/10/2.
// Copyright (c) 2015年 niaoren. All rights reserved.
//
#include <stdio.h>
#define ROW 7
#define COL 6
void print_mg(char mg[ROW][COL]){
for (int i=0; i<6; i++) {
for (int j=0; j<6; j++) {
printf("%c",mg[i][j]);
}
printf("\n");
}
}
int main(int argc, const char * argv[]) {
// insert code here...
printf("请输入wsad 分别表示上下左右\n");
char mg [ROW][COL] = {'#','#','#','#','#','#',
'#','0','#','#','#','#',
'#',' ','#',' ',' ',' ',
'#',' ','#',' ','#','#',
'#',' ',' ',' ','#','#',
'#','#','#','#','#','#',
};
print_mg(mg);
int y=1;
int x=1;
char road = ' ';
char temp;
char key;
char a[] = "sdsds";
while (1) {
scanf("%c",&key);
// getchar(); 吸收字符
switch (key) {
case 'W':
case 'w':
if(mg[y-1][x]==road){
temp = mg[y-1][x];
mg[y-1][x] = mg[y][x];
mg[y][x] = temp;
// print_mg(mg);
y--;
}
break;
case 'S':
case 's':
if(mg[y+1][x]==road){
temp = mg[y+1][x];
mg[y+1][x] = mg[y][x];
mg[y][x] = temp;
// print_mg(mg);
y++;
}
break;
case 'A':
case 'a':
if(mg[y][x-1]==road){
temp = mg[y][x-1];
mg[y][x-1] = mg[y][x];
mg[y][x] = temp;
// print_mg(mg);
x--;
}
break;
case 'D':
case 'd':
if(mg[y][x+1]==road){
temp = mg[y][x+1];
mg[y][x+1] = mg[y][x];
mg[y][x] = temp;
// print_mg(mg);
x++;
}
break;
default:
print_mg(mg);
if(x==ROW-2){
printf("成功过关_________");
return 0;
}
break;
case 'Q':
case 'q':
printf("_________");
return 0;
break;
}
}
return 0;
}
|
|