今天分享一个c++迷宫游戏的代码,废话不多说,上代码:
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
char maze[8][9]={
"########",
"#O #$$$#",
"# #$$$#",
"# X $#$#",
"#$ ##$ #",
"#$###$##",
"#$$ E#",
"########"
};
int main(){
char op;
int x=1,y=1,ex=3,ey=2,score=0;
srand(time(0));
for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
cout<<maze[i][j];
}
cout<<endl;
}
cout<<"score:"<<score<<endl;
bool done=false;
while(true){
op=getch();
if(op=='w'&&maze[x-1][y]!='#'){
maze[x][y]=' ';
x--;
}else if(op=='s'&&maze[x+1][y]!='#'){
maze[x][y]=' ';
x++;
}else if(op=='