Question
you have global variables for board, moves you are not using constants for items in the dungeon and moves rdirection could use a switch or
you have global variables for board, moves
you are not using constants for items in the dungeon and moves
rdirection could use a switch or an array of moves and be simpler -- just a suggestion
you are using a while true with break in setting traps, please recode differently
you are using single character names for variables, please redo with better names
you have == instead of = in checkMove
========
#include
#define MAX_SIZE 8
using namespace std;
char board[MAX_SIZE][MAX_SIZE]; int xP=-1,yP=-1; int xT=-1,yT=-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,int y,char m,char t){ bool ret=false; // for left if(m=='L'){ x--; if(x>=0){ ret=true; } } // for right if(m=='R'){ x++; if(x // random direction char rDirection(){ char ret=' '; int r=rand()%4; if(r==0){ret='L';} if(r==1){ret='R';} if(r==2){ret='U';} if(r==4){ret='D';} return(ret); } // monster move bool updateMosterMove(int _n,char p){ for(int i=0;i<_n;i++){ char ch=rDirection(); bool b=checkMove(xM[i],yM[i],ch,p); if(b==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,int y,char t){ char ret=' '; bool b=false; char m=' '; while(true){ cout<<" L (Left)"; cout<<" R (Right)"; cout<<" U (Upper)"; cout<<" D (Down)"; cout<<" Enter Your Move : "; cin>>m; // for valid move if(m=='L' || m=='R' || m=='U' || m=='D'){ b=checkMove(x,y,m,t); if(b==false){ cout<<" Wrong Move , Please enter correct move."; } else{ ret=m; break; } } // invalid user move else{ cout<<" Invalid move "; } } return ret; } // user move update in board void updateDungeon(int x,int y,char player,char m){ board[x][y]='.'; if(m=='L'){ x--; } if(m=='R'){ x++; } if(m=='D'){ y++; } if(m=='U'){ y--; } // place player board[x][y]=player; // update new move xP=x;yP=y; } // check monster eat player bool check(int _n){ bool ret=false; for(int i=0;i<_n;i++){ if(xM[i]==xP && yM[i]==yP){ ret=true; break; } } return ret; } // main function int main(){ srand(time(0)); createDungeon('G',8,'X',4); while(true){ showBoard(board); char m=getMove(xP,yP,'X'); updateDungeon(xP,yP,'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