#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;
}