请在列表里自己绘制迷宫
#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;
}
已测,(高端电脑)请放心食用