Question
======== You still have global variables. You still have bad formatting You are still using a while true statement --------- #include #include #include using namespace
========
You still have global variables.
You still have bad formatting
You are still using a while true statement
---------
#include
#define MAX_SIZE 8
char board[MAX_SIZE][MAX_SIZE]; //global matrix with MAX_SIZE 8 int x_Pos=-1,y_Pos=-1; int x_T=-1,y_T=-1;
int xM[MAX_SIZE],yM[MAX_SIZE];
void createDungeon(char player,int numberOfTrap,char treasure,int monstarNo) { // initialise for(int i=0;i // display board void showBoard(char theBoard[MAX_SIZE][MAX_SIZE]) { for(int i=0;i // check user move bool checkMove(int x_pos,int y_pos,char move,char t) { bool return_value=false; // for left if(move=='L'){ x_pos--; if(x_pos>=0){ return_value=true; } } // for right if(move=='R'){ x_pos++; if(x_pos // random direction char rDirection() { char return_char=' '; int random_number=rand()%4; if(random_number==0){return_char='L';} if(random_number==1){return_char='R';} if(random_number==2){return_char='U';} if(random_number==4){return_char='D';} return(return_char); } // monster move bool updateMosterMove(int _n,char p){ for(int i=0;i<_n;i++){ char ch=rDirection(); bool b_checkMove_value=checkMove(xM[i],yM[i],ch,p); if(b_checkMove_value==true){ board[xM[i]][yM[i]]='.'; if(ch=='L'){xM[i]--;} if(ch=='R'){xM[i]++;} if(ch=='U'){yM[i]--;} if(ch=='D'){yM[i]++;} board[xM[i]][yM[i]]='M'; } } } // user move char getMove(int x_pos,int y_pos,char t){ char return_char=' '; bool b_checkMove_value=false; char move=' '; while(true){ cout<<" L (Left)"; cout<<" R (Right)"; cout<<" U (Upper)"; cout<<" D (Down)"; cout<<" Enter Your Move : "; cin>>move; // for valid move if(move=='L' || move=='R' || move=='U' || move=='D'){ b_checkMove_value=checkMove(x_pos,y_pos,move,t); if(b_checkMove_value==false){ cout<<" Wrong Move , Please enter correct move."; } else{ return_char=move; break; } } // invalid user move else{ cout<<" Invalid move "; } } return return_char; } // user move update in board void updateDungeon(int x_pos,int y_pos,char player,char move){ board[x_pos][y_pos]='.'; if(move=='L'){ x_pos--; } if(move=='R'){ x_pos++; } if(move=='D'){ y_pos++; } if(move=='U'){ y_pos--; } // place player board[x_pos][y_pos]=player; // update new move x_Pos=x_pos;y_Pos=y_pos; } // check monster eat player bool check(int _n){ bool return_value=false; for(int i=0;i<_n;i++){ if(xM[i]==x_Pos && yM[i]==y_Pos){ return_value=true; break; } } return return_value; } // main function int main(){ srand(time(0)); createDungeon('G',8,'X',4); while(true){ showBoard(board); char m=getMove(x_Pos,y_Pos,'X'); updateDungeon(x_Pos,y_Pos,'G',m); cout<
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started