Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

======== 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 #include #include using namespace std;

#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=0) { return_value=true; } } // board update possible by new move if(return_value==true){ if(board[x_pos][y_pos]=='.' || board[x_pos][y_pos]==t){ return_value==true; } else{ return_value=false; } } return return_value; }

// 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<>again; if(again=='Y' || again=='y'){ createDungeon('G',8,'X',4); } else{ break; } } else{ if(x_Pos==x_T && y_Pos==y_T){ cout<<" ******^^^^^^****** "; showBoard(board); cout<<" You got Treasure."; cout<<" Want to play again [y/n]"; char again; cin>>again; if(again=='Y' || again=='y'){ createDungeon('G',8,'X',4); } else{ break; } } } } cout<<" GAME OVER"; return(0); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions