帖主用一点小基础做了一个小迷宫......其实都说不上是迷宫吧......反正,你可以用WASD键去控制“H”
废话不多说,上代码!
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
int main(){
char keybox;
int x = 2;
int y = 2;
int no1_y = 2;
int no1_x = 3;
int no2_y = 3;
int no2_x = 5;
int no3_y = 4;
int no3_x = 3;
/*
地图:
******
*H*--*
*---**
*-*--*
******
*/
cout<<"******"<<endl;
cout<<"*H*--*"<<endl;
cout<<"*---**"<<endl;
cout<<"*-*--*"<<endl;
cout<<"******"<<endl;
while(true){
keybox = getch();
if (keybox == 'a' || keybox == 'A') x --; x == no1_x && y == no1_y || x == no2_x && y == no2_y|| x == no3_x && y == no3_y|| x < 2?x++:x = x;
if (keybox == 's' || keybox == 'S') y ++; x == no1_x && y == no1_y || x == no2_x && y == no2_y|| x == no3_x && y == no3_y|| y > 4?y--:y = y;
if (keybox == 'd' || keybox == 'D') x ++; x == no1_x && y == no1_y || x == no2_x && y == no2_y|| x == no3_x && y == no3_y|| x > 5?x--:x = x;
if (keybox == 'w' || keybox == 'W') y --; x == no1_x && y == no1_y || x == no2_x && y == no2_y|| x == no3_x && y == no3_y|| y < 2?y++:y = y;
system("cls");
cout<<"******"<<endl;
if (x == 2 && y == 2){
cout<<"*H*--*"<<endl;
cout<<"*---**"<<endl;
cout<<"*-*--*"<<endl;
}
else if (x == 2 && y == 3){
cout<<"*-*--*"<<endl;
cout<<"*H--**"<<endl;
cout<<"*-*--*"<<endl;
}
else if (x == 2 && y == 4){
cout<<"*-*--*"<<endl;
cout<<"*---**"<<endl;
cout<<"*H*--*"<<endl;
}
else if (x == 3 && y == 3){
cout<<"*-*--*"<<endl;
cout<<"*-H-**"<<endl;
cout<<"*-*--*"<<endl;
}
else if (x == 4 && y == 3){
cout<<"*-*--*"<<endl;
cout<<"*--H**"<<endl;
cout<<"*-*--*"<<endl;
}
else if (x == 4 && y == 2){
cout<<"*-*H-*"<<endl;
cout<<"*---**"<<endl;
cout<<"*-*--*"<<endl;
}
else if (x == 5 && y == 2){
cout<<"*-*-H*"<<endl;
cout<<"*---**"<<endl;
cout<<"*-*--*"<<endl;
}
else if (x == 4 && y == 4){
cout<<"*-*--*"<<endl;
cout<<"*---**"<<endl;
cout<<"*-*H-*"<<endl;
}
else if (x == 5 && y == 4){
cout<<"*-*--*"<<endl;
cout<<"*---**"<<endl;
cout<<"*-*-H*"<<endl;
}
cout<<"******"<<endl;
cout<<x<<','<<y;
}
}