#include <stdio.h>
#include <stdbool.h>
char map[5][5] = {
{'*', '*', '*', '*', '*'},
{'*', ' ', ' ', ' ', '*'},
{'*', ' ', ' ', ' ', '*'},
{'*', ' ', ' ', '6', '*'},
{'*', '*', '*', '*', '*'}
};
int x = 1;
int y = 1;
bool gameover = false;
bool gamewon = false;
void drawMap() {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (i == y && j == x) {
printf("W");
} else {
printf("%c", map[i][j]);
}
}
printf("\n");
}
}
void processInput() {
char dddd;
printf("移动玩家,请输入方向W,A,S,D\n");
scanf("%s", &dddd);
switch (dddd) {
case'W':
case'w':
if (y - 1 >= 0 && map[y - 1][x] != '*') {
y--;
}
break;
case'A':
case'a':
if (x - 1 >= 0 && map[y][x] != '*') {
x--;
}
break;
case'S':
case's':
if (y + 1 < 5 && map[y + 1][x] != '*') {
y++;
}
break;
case'D':
case'd':
if (x + 1 < 5 && map[y][x + 1] != '*') {
x++;
}
break;
default:
printf("输入有误!\n");
break;
}
}
void checkGameStatus() {
if (x == 3 && y == 3) {
gamewon = true;
gameover = true;
}
}
int main() {
printf("欢迎来到闯关游戏\n");
while (!gameover) {
drawMap();
processInput();
checkGameStatus();
}
if (gamewon) {
printf("恭喜获胜\n");
} else {
printf("输了\n");
}
return 0;
}
移动
原创wx641ed5d0bdd07 ©著作权
©著作权归作者所有:来自51CTO博客作者wx641ed5d0bdd07的原创作品,请联系作者获取转载授权,否则将追究法律责任

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
【移动】
Font Boosting
JAVA