#include<stdio.h>
int main(){
char map[6][12]={
{'#','#','#','#','#','#','#','#','#','#','#','#'},
{'D',' ','#','#',' ',' ',' ',' ',' ','#','#','#'},
{'#',' ','#','#',' ','#','#','#',' ','#',' ',' '},
{'#',' ','#',' ',' ','#','#',' ',' ','#',' ','#'},
{'#',' ',' ',' ','#','#','#',' ','#','#',' ','#'},
{'#','#','#','#','#','#','#',' ',' ',' ',' ','#'}
};
for (int i = 0; i < 6; i++) { //打印地图
for (int j = 0; j < 12; j++) {
printf("%c",map[i][j]);
}
printf("\n");
}
int currentX = 1;
int currentY = 0;
char ch;
printf("请移动小人w:上\ts:下\ta:左\td:右\tq:退出\n");
while (1) {
if (currentY == 11) {
printf("哇哦,你逃出去了\n");
return 0;
}
scanf("%c",&ch);
switch (ch) {
case 'w' :
case 'W' :
if (map[currentX - 1][currentY] == ' ') {
int temp = map[currentX - 1][currentY];
map[currentX - 1][currentY]=map[currentX][currentY];
map[currentX][currentY]=temp;
currentX--;
for (int i = 0; i < 6; i++) { //打印地图
for (int j = 0; j < 12; j++) {
printf("%c",map[i][j]);
}
printf("\n");
}
}
break;
case 's' :
case 'S' :
if (map[currentX + 1][currentY] == ' ') {
int temp = map[currentX + 1][currentY];
map[currentX + 1][currentY]=map[currentX][currentY];
map[currentX][currentY]=temp;
currentX++;
for (int i = 0; i < 6; i++) { //打印地图
for (int j = 0; j < 12; j++) {
printf("%c",map[i][j]);
}
printf("\n");
}
}
break;
case 'a' :
case 'A' :
if (map[currentX][currentY - 1] == ' ') {
int temp = map[currentX][currentY - 1];
map[currentX ][currentY - 1]=map[currentX][currentY];
map[currentX][currentY]=temp;
currentY--;
for (int i = 0; i < 6; i++) { //打印地图
for (int j = 0; j < 12; j++) {
printf("%c",map[i][j]);
}
printf("\n");
}
}
break;
case 'd' :
case 'D' :
if (map[currentX][currentY + 1] == ' ') {
int temp = map[currentX][currentY + 1];
map[currentX][currentY + 1]=map[currentX][currentY];
map[currentX][currentY]=temp;
currentY++;
for (int i = 0; i < 6; i++) { //打印地图
for (int j = 0; j < 12; j++) {
printf("%c",map[i][j]);
}
printf("\n");
}
}
break;
case 'q' :
case 'Q' :
printf("游戏正在退出...\n");
printf("游戏已经推出!\n");
return 0;
}
}
} |
|