木乃伊迷宫(改)

来源:互联网 发布:软件英文怎么说 编辑:程序博客网 时间:2024/05/21 12:50


#include<iostream>
#include<windows.h>
using namespace std;

int rrow=3;int rcol=4;//人的位置
int mrow=1;int mcol=14;//木乃伊位置
int crow=8;int ccol=11;//出口位置
char M[10][17]=
{
    {"################"},
 {"#            #m#"},
 {"#            # #"},
 {"#   r        # #"},
 {"#            # #"},
 {"#            # #"},
 {"#            # #"},
 {"#            # #"},
 {"#          c   #"},
 {"################"}
};

void showmap();
void manmove(char x);
void mnymove();

//显示地图
void showmap()
{
 int i,j;
 for(i=0;i<10;i++)
 {
  for(j=0;j<16;j++)
  {
   cout<<M[i][j];
  }
  cout<<endl;
 }
}
//人走一步
void manmove(char x)
{
 int r,c,n;
 r=rrow;c=rcol;
 if(x=='a')
 {
  c=c-1;
 }
 else if(x=='s')
 {
  r=r+1;
 }
 else if(x=='d')
 {
  c=c+1;
 }
 else if(x=='w')
 {
  r=r-1;
 }
 if(M[r][c]!='#')
 {
  M[rrow][rcol]=' ';
  rrow=r;
  rcol=c;
  M[rrow][rcol]='r';
 }
}
//木乃伊走一步
void mnymove()
{
 int r,c;
 r=mrow;c=mcol;
 if(mrow<rrow)
 {
  r=r+1;
 }
 else if(mrow>rrow)
 {
  r=r-1;
 }
 else
 {
  if(mcol>rcol)
  {
   c=c-1;
  }
  else if(mcol<rcol)
  {
   c=c+1;
  }
 }
 if(M[r][c]!='#')
 {
  M[mrow][mcol]=' ';
  mrow=r;
  mcol=c;
  M[mrow][mcol]='m';
 }
}

//主控
int main()
{
 while(1)
 {
  showmap();
  char n;
  cin>>n;
  manmove(n);
  mnymove();
  mnymove();
  if(rrow==mrow&&rcol==mcol)
  {
   cout<<"You Lose!"<<endl;
   break;
  }
  if(rrow==crow&&rcol==ccol)
  {
   cout<<"You Win!"<<endl;
   break;
  }
  system("cls");
 }
}

原创粉丝点击