走迷宫

发布时间 2023-08-07 19:11:05作者: niuzeyu1
#include<cstdio>
#include<conio.h>
#include<windows.h>
char a[25][25]= {"############",
                 "#O#    #  ##",
                 "#   ## # # #",
                 "#####  ### #",
                 "#     #### #",
                 "# #####   ##",
                 "#       #   ",
                 "############",};
void Hide(){
	system("color c1");
	HANDLE              hOut;
	CONSOLE_CURSOR_INFO curInfo;
	
	hOut=GetStdHandle(STD_OUTPUT_HANDLE);
	curInfo.dwSize=1;
	curInfo.bVisible=0;
	SetConsoleCursorInfo(hOut,&curInfo);
}
void Set(){
	HANDLE hOut;
	COORD pos={0,0};
	hOut=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hOut,pos);
}
void Welcome(){
	printf("\n\n                欢迎游玩:");
	printf("\n\n                走 迷 宫");
	printf("\n\n             请按任意键开始");
	getch();
	system("cls"); 
}
int main() {
	Hide();
	Welcome();
	int x,y;
	char ch;
	x=1,y=1;
	for(int i=0; i<=7; i++)
		puts(a[i]);
	while(1) {
		ch=getchar();
		if(ch=='s') {
			if(a[x+1][y]==' ') {
				a[x][y]=' ';
				x++;
				a[x][y]='O';
			}
		} else if(ch=='w') {
			if(a[x-1][y]==' ') {
				a[x][y]=' ';
				x--;
				a[x][y]='O';
			}
		} else if(ch=='d') {
			if(a[x][y+1]==' ') {
				a[x][y]=' ';
				y++;
				a[x][y]='O';
			}
		} else if(ch=='a') {
			if(a[x][y-1]==' ') {
				a[x][y]=' ';
				y--;
				a[x][y]='O';
			}
		}
		Set();
		for(int i=0; i<=7; i++)
			puts(a[i]);
		if(x==6 && y==11)
			break;
	}
	printf("真厉害!!!");
	Sleep(1000);
}