oIu4gvYQQbYbdj3CmlCX1oRQQn4r8Yec
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
string username;
int score;
char ma[55][55]={
"#######################",
"#H# # # # # # #",
"# # # # # # # # #",
"# # # # # # # # # # #",
"# # # # # # # # # #",
"# # # # # # #",
"# # # # # # # # #",
"# # # # # # # # # # #",
"# # # # # # # # # #",
"# # # # # # # #",
"# # # # # # # # #",
"# # # # # # # # # #",
"# # # # # # # # # #",
"# # # # # # # #",
"# # # # # # # # # #",
"# # # # # # # # # #",
"# # # # # # # # #",
"# # # # # # # #",
"# # # # # # # # # # #",
"# # # # # #E#",
"#######################",
};
char mb[50][50];
bool col[50][50];
void login(){
printf("hi!what is your name?\n");
cin>>username;
system("cls");
}
void Init(){
for(int i=0;i<=30;i++)
for(int j=0;j<=30;j++)
mb[i][j]=ma[i][j],col[i][j]=0;
}
void print(){
system("cls");
printf("###################\n");
printf("user:");cout<<username<<endl;
if(score<=10)puts("level 1--The Beginner of the Maze");
else if(score<=20)puts("level 2--The Old Hand of the Maze");
else if(score<=50)puts("level 3--The Master of the Maze");
else puts("level 4--The god of the Maze");
printf("score:%05d\n",score);
puts("move by w,a,s,d");
puts("if you want to leave,say(g)");
for(int i=0;i<=21;i++)
puts(mb[i]);
}
int nt[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
int chose[24][4]={
{0,1,2,3},{0,1,3,2},{0,2,1,3},{0,2,3,1},{0,3,1,2},{0,3,2,1},
{1,2,3,0},{1,2,0,3},{1,0,2,3},{1,0,3,2},{1,3,0,2},{1,3,2,0},
{2,1,0,3},{2,1,3,0},{2,0,1,3},{2,0,3,1},{2,3,1,0},{2,3,0,1},
{3,0,1,2},{3,0,2,1},{3,1,0,2},{3,1,2,0},{3,2,1,0},{3,2,0,1}
};
int steps;
bool dfs(int tx,int ty,int step){
if(step>steps)return 0;
col[tx][ty]=1;
int t=rand()%24;
if(ma[tx][ty]=='E'&&abs(step-steps)<=5)return 1;
for(int i=0;i<=3;i++)
{
int nx=tx+nt[chose[t][i]][0];
int ny=ty+nt[chose[t][i]][1];
if(ma[nx][ny]=='#'||col[nx][ny]||(ma[nx][ny]=='E'&&steps-step>5))continue;
if(dfs(nx,ny,step+1))return 1;
}
col[tx][ty]=0;
return 0;
}
void make_map(){
Init();
steps=80;
dfs(1,1,0);
for(int i=1;i<=100;i++)
{
int tx,ty;
while(1)
{
tx=rand()%20+1;
ty=rand()%21+1;
if(mb[tx][ty]==' '&&!col[tx][ty])
break;
}
mb[tx][ty]='#';
}
}
int x=1,y=1;
bool move(char mv){
mb[x][y]=' ';bool flag=0;
if(mv=='w'&&mb[x-1][y]!='#')x--,flag=1;
if(mv=='a'&&mb[x][y-1]!='#')y--,flag=1;
if(mv=='s'&&mb[x+1][y]!='#')x++,flag=1;
if(mv=='d'&&mb[x][y+1]!='#')y++,flag=1;
mb[x][y]='H';
return flag;
}
void colo(){
if(score<=10)system("color 70");
else if(score<=20)system("color 34");
else if(score<=50)system("color E1");
else system("color 6F");
}
int main(){
srand(time(NULL));
login();
system("cls");
puts("Are you ready?");
puts("Yes(y) No(n)");
char c=getch();
if(c=='n'){
system("cls");
puts("Byebye!");
return 0;
}
while(1){
make_map();
x=1,y=1;
colo();
while(1){
print();
if(x==19&&y==21){
system("cls");
puts("You Win!!!");
score++;
break;
}
char mv=getch();
move(mv);
if(mv=='g'){
system("cls");
puts("You have already given up on it!");
break;
}
}
puts("Again?");
puts("if you want to finish the game,you will lose your score.");
puts("Yes(y) No(n)");
c=getch();
if(c=='n'){
system("cls");
puts("Byebye!");
return 0;
}
}
return 0;
}