0

I have written a program that will generate a random maze and solve it. The program uses a multidimensional array of a class that holds bool values for each wall, whether or not to show an * for the path taken, and if it is a dead end.

here is the class

#include <cstdlib>

using namespace std;
class MazeCell
{
public:

	// ============================================================================================
	// Routine: Class Constructor
	// Purpose: Allows setting the default values of the class when instantiated by the host.
	// ============================================================================================
	MazeCell()
	{
		wallNORTH = false;
		wallEAST = false;
		wallSOUTH = false;
		wallWEST = false;
		path = false;
		deadEnd = false;
	}
	// ============================================================================================
	// Routine: SetWalls
	// Purpose: Allows setting (or updating) the values of the class references at any time.
	// ============================================================================================
	void SetWalls(bool pNorth, bool pEast, bool pSouth, bool pWest, bool pPath, bool pDeadEnd)
	{
		wallNORTH = pNorth;
		wallEAST = pEast;
		wallSOUTH = pSouth;
		wallWEST = pWest;
		path = pPath;
		deadEnd = pDeadEnd;
	}
	void SetNorth(bool pNorth){
		wallNORTH = pNorth;
	}
	void SetEast(bool pEast){
		wallEAST = pEast;
	}
	void SetSouth(bool pSouth){
		wallSOUTH = pSouth;
	}
	void SetWest(bool pWest){
		wallWEST = pWest;
	}
	void SetPath(bool pPath){
		path = pPath;
	}
	void SetDeadEnd(bool pDeadEnd){
		deadEnd = pDeadEnd;
	}
	// ============================================================================================
	// Routine: Get[Wall]
	// Purpose: Function returning if wall is open or closed.
	// ============================================================================================
	bool GetNORTH() { return wallNORTH; }
	bool GetEAST() { return wallEAST; }
	bool GetSOUTH() { return wallSOUTH; }
	bool GetWEST() { return wallWEST; }
	bool GetPath() { return path; }
	bool GetDeadEnd() { return deadEnd; }

private:
	// ===[ Internal Class Declarations ]==========================================================
    bool wallNORTH;       // Represents whether or not the NORTH wall is open or blocked
	bool wallEAST;        // Represents whether or not the EAST wall is open or blocked
	bool wallSOUTH;       // Represents whether or not the SOUTH wall is open or blocked
	bool wallWEST;  	  // Represents whether or not the WEST wall is open or blocked
	bool path;
	bool deadEnd;
};

class pos
{
public:
	void curPos(int pX, int pY)
	{
		row = pX;
		col = pY;
	}
private:
	int row, col;
};

and here is the declare the array.

const int MazeHEIGHT = 10;
const int MazeWIDTH = 10;
MazeCell theMaze[MazeHEIGHT][MazeWIDTH];

the problem is that instead of using a const int value for the width and height, I want to take in the users input and then make the array. Right now i have the array as a global of type class. I tried to make the array using pointers but had no success. Do i need to do away with the array and if so what should i use.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by firstPerson
0

There are a couple of options.

1) Use std::vector< std::vector >
2) Use dynamic arrays
3) Create a static array, with big enough size, and get the limited user's input as size. And use that variable, as the max size.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.