今日学习了bfs,做了很多走迷宫的题目,突发奇想,写了一个123行的小游戏。
功能:实现固定地图走迷宫,可以选择不同语言版本
#include<bits/stdc++.h>
#include<windows.h>
char mp[6][8]={{'.','#','#','#','.','.','#','.'},{'.','.','.','#','#','.','#','.'},{'#','#','.','#','#','.','.','#'},{'#','#','.','.','.','.','.','.'},{'#','#','#','#','#','#','.','#'},{'.','.','.','#','.','#','.','.'}};
int vis[4][2]={{0,-1},{0,1},{-1,0},{1,0}};
using namespace std;
int main(){
cout<<"中国人?american? 用01来选择国籍 Please use the 01 to choose the contrie"<<endl;
int res;
cin>>res;
if(res==1){
cout<<"掉下去啦…………………………………………"<<endl;
Sleep(2000);
cout<<"你掉进了一个迷宫"<<endl;
cout<<"你需要逃出去"<<endl;
Sleep(2000);
system("cls");
cout<<"你在@的位置,尝试逃出去!!"<<endl;
cout<<"通过wsad控制方向! w为上,s为下,a为左,d为右"<<endl;
Sleep(2000);
system("cls");
}
else {
cout<<"falling…………………………………………"<<endl;
Sleep(2000);
cout<<"you are in a maze"<<endl;
cout<<"you should leave."<<endl;
Sleep(2000);
system("cls");
cout<<"you are on the place of the @.try to leave!!"<<endl;
cout<<"use wsad to contrl the way! w is up,s if down,a is left,d is right";
Sleep(2000);
system("cls");
}
mp[0][0]='@';
for(int i=0;i<6;i++){
for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
cout<<endl;
}
int x,y;
x=y=0;
while(y<6&&x<7){
char ch;
cin>>ch;
if(ch=='w'){
if(mp[y+vis[0][1]][x+vis[0][0]]=='#'){
cout<<"NOWAY!"<<endl;
}
else {
system("cls");
mp[y][x]='.';
x+=vis[0][0];
y+=vis[0][1];
mp[y][x]='@';
for(int i=0;i<6;i++){
for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
cout<<endl;
}
}
}
else if(ch=='s'){
if(mp[y+vis[1][1]][x+vis[1][0]]=='#'){
cout<<"NOWAY!"<<endl;
}
else {
system("cls");
mp[y][x]='.';
x+=vis[1][0];
y+=vis[1][1];
mp[y][x]='@';
for(int i=0;i<6;i++){
for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
cout<<endl;
}
}
}
else if(ch=='a'){
if(mp[y+vis[2][1]][x+vis[2][0]]=='#'){
cout<<"NOWAY!"<<endl;
}
else {
system("cls");
mp[y][x]='.';
x+=vis[2][0];
y+=vis[2][1];
mp[y][x]='@';
for(int i=0;i<6;i++){
for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
cout<<endl;
}
}
}
else if(ch=='d'){
if(mp[y+vis[3][1]][x+vis[3][0]]=='#'){
cout<<"NOWAY!"<<endl;
}
else {
system("cls");
mp[y][x]='.';
x+=vis[3][0];
y+=vis[3][1];
mp[y][x]='@';
for(int i=0;i<6;i++){
for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
cout<<endl;
}
}
}
}
if(res==1){
cout<<"太棒了!你成功逃了出去!"<<endl;
cout<<"你想要关机吗?(0,1)选择"<<endl;
}
else {
cout<<"good job!! you leaved"<<endl;
cout<<"do you want to shutdown?(0,1)to choose"<<endl;
}
int s;
cin>>s;
if(s==0)return 0;
if(s==1)system("shutdown -p");
}