#include <iostream>
#include <ctime>
#include <windows.h>/* Sleep(1000);*/
#include <cstdlib>/* srand (time(0));*/
using namespace std;
int main()
{
cout<<"找宝藏游戏,欢迎您!"<<endl;
cout<<"如果超出迷宫会被虚空吞噬"<<endl;
cout<<"1进入游戏,2退出游戏!"<<endl;
/*char ch;
xuanze: ch=getchar();
char y,n;
*/
xuanze:int ch;
cin>>ch;
if(ch==1)
{system("cls");
goto game;
}
else if(ch==2)
{ system("cls");
cout<<"欢迎下次光临!";
Sleep(1000);
goto end;
}
else{
system("cls");
cout<<"输入错误,请重新进入游戏!"<<endl;
Sleep(1000);
goto end;
};
game:cout<<"请选择迷宫大小 n * n 的规格"<<endl;
cout<<"n =";
int n;
cin>>n;
system("cls");
int a[3];
srand (time(0));
int wo,baozang;
for(int i=0;i<=1;i++)
{
a[i]=rand()%n*n+1;
};
wo=a[0];
baozang=a[1];
for(int i=1;i<=n*n;i++)
{
if(i%n==0)
{ cout<<' '<<'*'<<' ';
cout<<endl;
}
else if(i==wo)
{
cout<<' '<<'#'<<' ';
}
else {
cout<<' '<<'*'<<' ';
}
};
yidong: while(baozang!=wo)
{
char b[1000];
switch(b[1000]=getchar())
{
case'a': wo=wo-1;break;
case'd': wo=wo+1;break;
case'w': wo=wo-n;break;
case's': wo=wo+n;break;
}
if(wo>n*n||wo<=0)
{
cout<<"超出地图,被虚空吞噬!" ;
Sleep(1000);
goto end;
}
system("cls");
for(int i=1;i<=n*n;i++)
{
if(i%n==0&&i!=wo)
{ cout<<' '<<'*'<<' ';
cout<<endl;
}
else if(i%n==0&&i==wo)
{
cout<<' '<<'#'<<' ';
cout<<endl;
}
else if(i==wo)
{
cout<<' '<<'#'<<' ';
}
else {
cout<<' '<<'*'<<' ';
}
};
if(baozang==wo)
{
cout<<"您找到宝藏了";
Sleep(1000);
}
}
end: return 0;
}