迷宫
#include <iostream> #include <iomanip> using namespace std; int main(){ int c,d,h,s,u,t; char f; cout<<"请输入棋盘的大小"<<endl; cin>>c>>d; cout<<"请输入人物的坐标"<<endl; cin>>h>>s; while(u==0||t==0){ cout<<"请输入箱子的坐标 输入0结束"<<endl; cin>>u>>t; while(1){ for(int i=0;i<c;i++){ for(int j=0;j<d;j++){ if(i==h&&j==s){ cout<<setw(3)<<"A"; }else if(i==u&&j==t){ cout<<setw(3)<<"@"; }else{ cout<<setw(3)<<"."; } cout<<"wasd 四个方向移动"<<endl; cin>>f; if(f=='W'||f=='w'){ h--; if(h<=0) h=0; if(s==t&&h==u){ h++; } }else if(f=='S'||f=='s'){ h++; if(h>=c) h-=1; if(s==t&&h==u){ h--; } }else if(f=='a'||f=='A'){ s--; if(s<0) s=0; if(s==t&&h==u){ s++; } }else if(f=='D'||f=='d'){ s++; if(s>=d) s-=1; if(s==t&&h==u){ s--; } }else if(f=='q'||f=='Q'){ break; } } cout<<endl; } system("cls"); } } return 0; }