一个未完成的迷宫模板
  • 板块灌水区
  • 楼主MA_master
  • 当前回复6
  • 已保存回复6
  • 发布时间2022/7/29 11:49
  • 上次更新2023/10/27 17:53:39
查看原帖
一个未完成的迷宫模板
677656
MA_master楼主2022/7/29 11:49

请在列表里自己绘制迷宫

对性能要求较高,低端电脑请勿进入!!!

#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>

#define forever while(true)
#define jumpout break;
#define endmain return 0

using namespace std;
string m[10][15]={
{
"###############",
"# #      #    #",
"# # ####  # # #",
"# # #   # # #  ",
"#   # # # # # #",
"### # #   # # #",
"#   # ##### ###",
"# # #       # #",
"# ########### #",
"# #    #      #",
"#   ##   #### #",
"# ########    #",
"# #   #    ####",
"#   #   #     #",
"###############",
},

{
"###############",
"#           #  ",
"########### # #",
"#           # #",
"# ########### #",
"#           # #",
"########### # #",
"#           # #",
"# ########### #",
"#           # #",
"########### # #",
"#           # #",
"# ########### #",
"#             #",
"###############",
},

{
"###############",
"#              ",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"###############",
},

{
"###############",
"#              ",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"###############",
},

{
"###############",
"#              ",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"###############",
},

{
"###############",
"#              ",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"###############",
},

{
"###############",
"#              ",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"###############",
},

{
"###############",
"#              ",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"###############",
},

{
"###############",
"#              ",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"###############",
},

{
"###############",
"#              ",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"#             #",
"###############",
}

};
int x=1,y=1,g=0,g_max=2;
long double begtime=0;
LARGE_INTEGER t1,t2,tc;

void print()
{
	system("cls");
	QueryPerformanceCounter(&t2);
 	long double time=(long double)(t2.QuadPart-t1.QuadPart)/(long double)tc.QuadPart;
	cout<<"time: "<<time<<" s"<<endl;

	for(int i=0;i<15;i++)
	{
		for(int j=0;j<15;j++)
		{
			if(i==x&&j==y) cout<<'@';
			else cout<<m[g][i][j];
		}
		cout<<endl;
	}
	cout<<"     LV="<<((g+1)<10?"0":"")<<g+1;
}
int main()
{
	cout<<"Please Wait";
	system("cls");
	
	QueryPerformanceFrequency(&tc);
	QueryPerformanceCounter(&t1);
	forever
	{
		print();
		char c;
		if(_kbhit()) c=_getch();
		switch(c)
		{
			case 'd':
				if((m[g][x][y+1]!='#'))
				{
					y+=1;
				}
				jumpout;
			case 'a':
				if(!(m[g][x][y-1]=='#'))
				{
					y-=1;
				}
				jumpout;
			case 's':
				if(!(m[g][x+1][y]=='#'))
				{
					x+=1;
				}
				jumpout;
			case 'w':
				if(!(m[g][x-1][y]=='#'))
				{
					x-=1;
				}
				jumpout;
			case 'r':
				g=0,x=1,y=1;
				QueryPerformanceFrequency(&tc);
				QueryPerformanceCounter(&t1);
				jumpout;
		}
		c='\0';
		Sleep(50);
		if(y==14)
		{
			g++;
			x=1,y=1;
			print();
		}
		if(g>=g_max)
		{
			system("cls");
			Sleep(1000);
			cout<<"You Win"<<endl;
			QueryPerformanceCounter(&t2);
		    long double time=(long double)(t2.QuadPart-t1.QuadPart)/(long double)tc.QuadPart;
		    time-=1;
			int minute=time/60;
		    cout<<"You use "<<time<<" seconds"<<endl;
			jumpout;
		}
		if((long double)(t2.QuadPart-t1.QuadPart)/(long double)tc.QuadPart>300)
		{
			system("cls");
			Sleep(1000);
			cout<<"You lose"<<endl;
			cout<<"Time Limit Error";
			jumpout;
		}
	}
	
	
	endmain;
}

已测,(高端电脑)请放心食用

2022/7/29 11:49
加载中...