中级守护
#include<bits/stdc++.h>
#include<stdio.h>
#include<conio.h>
#include <windows.h>
using namespace std;
string s[505]={
"#@######### ",
"# ## ## # #",
"## # ### #",
"##Q# ####Q###",
"# # ## ###",
"##Q ## Q####",
"### Q ######",
"##############"
};
//@坐标为s[0][1]
//胜利为s[1][7]
void sl(string s){
for(int i=0;i<s.size();i++){
cout<<s[i];
Sleep(20);
}
}
void guize(){
string gui[15]={"a向左行一格\n",
"d向右行一格\n",
"s向下行一格\n",
"w向上行一格\n",
"若前方有障碍(Q)",
"z键可以打破它,若碰到就会身亡\n\n"};
for(int i=0;i<=5;i++)
sl(gui[i]);
}
int main(){
MessageBox(NULL,TEXT("欢迎来到<<迷宫>>"),TEXT("迷宫"),MB_OK);
char a;
int x=0,y=1,p=0,q=12;
guize();
system("pause");
system("cls");
system("color 2");
for(int i=0;i<12;i++)
cout<<s[i]<<endl;
while(x!=p||y!=q){
a=getch();
if(a=='a'||a=='A'){
if(s[x][y-1]=='Q'){
system("cls");
cout<<"你**了!!";
Sleep(800);
return 0;
}
if(s[x][y-1]!='#'){
s[x][y]=' ';
y--;
s[x][y]='@';
}
}else if(a=='d'||a=='D'){
if(s[x][y+1]=='Q'){
system("cls");
cout<<"你**了!!";
Sleep(800);
return 0;
}
if(s[x][y+1]!='#'){
s[x][y]=' ';
y++;
s[x][y]='@';
}
}else if(a=='s'||a=='S'){
if(s[x+1][y]=='Q'){
system("cls");
cout<<"你**了!!";
Sleep(800);
return 0;
}
if(s[x+1][y]!='#'){
s[x][y]=' ';
x++;
s[x][y]='@';
}
}else if(a=='w'||a=='W'){
if(s[x-1][y]=='Q'){
system("cls");
cout<<"你**了!!";
Sleep(800);
return 0;
}
if(s[x-1][y]!='#'){
s[x][y]=' ';
x--;
s[x][y]='@';
}
}
else if(a=='z'||a=='Z'){
if(s[x-1][y]=='Q')
s[x-1][y]=' ';
else if(s[x+1][y]=='Q')
s[x+1][y]=' ';
else if(s[x][y-1]=='Q')
s[x][y-1]=' ';
else if(s[x][y+1]=='Q')
s[x][y+1]=' ';
}
system("cls");
for(int i=0;i<12;i++)
cout<<s[i]<<endl;
}
Sleep(500);
system("cls");
string s1,s2,s3,s4;
system("color 1");
s1="迷 迷 宫 宫 宫 宫宫宫\n";
s2=" 迷 迷 迷迷迷 迷 迷 宫 宫 宫 宫 宫\n";
s3=" 迷 迷 迷 迷 迷 宫 宫 宫 宫 宫 宫 宫\n";
s4=" 迷 迷迷迷 迷迷迷 宫 宫 宫 宫 宫\n";
cout<<s1<<s2<<s3<<s4;
Sleep(1000);
return 0;
}