I'm creating a maze class using pointers and recursion and having some trouble setting up my number of Position functions. Maze.h: #ifndef MAZE_H #define MAZE_H /* * The allowed directions of travel within the Maze. */ enum direction {west, north, south, east}; /* * Represents a location within the Maze. */ struct coordinates { int x; int y; }; class Maze { public: Maze(); /* * It allows you to pick a seed for the pseudo-random number * generator and a size. A small size makes it easier for you * to see what your program is doing. Every instance with the same * seed and size is guaranteed to have the same Maze. */ Maze(int seed, int size); Maze(const Maze &); Maze&operator=(const Maze); ~Maze(); /* * numberOfPositions() returns a count which will hold the length * of the maximum possible path through the Maze. It's useful for * allocating enough characters to contain the successful path * through the Maze. */ int numberOfPositions(); /* * startingPosition() provides the caller with the coordinates * of the entry into the Maze. */ void startingPosition(struct coordinates &where); /* * move() takes a direction of travel and the coordinates from * which to travel as input. The return value lets the caller * know whether they were permitted to travel in that direction * from those coordinates. If true, the coordinates are changed * to the new location in the Maze. If false, either the given * coordinates are invalid or travel in the given direction from * the given coordinates is not allowed. If false, the given * coordinates is unchanged. */ bool move(enum direction whichWay, struct coordinates &where); /* * escaped() lets the caller know whether the given location is * the exit of the Maze. */ bool escaped(const struct coordinates &where); private: int Seed; int Size; struct coordinates start; int **maze; char *path; }; #endif Maze.cpp: #include #include #include "Maze.h" using namespace std; Maze::Maze() { cout << " inside the default constructor " << endl; } Maze::Maze(int seed, int size) { Size = size; Seed = seed; } int Maze::numberOfPositions() { coordinates.x=0; coordinates.y=0; if ((coordinates.x && coordinates.y) == -1) { return 0; } for (int i=0; i< maze.size(); i++){ if (coordinates.y == 0){ coordinates.y == 1; } else { break; } } }
I'm creating a maze class using pointers and recursion and having some trouble setting up my number of Position functions.
Maze.h:
#ifndef MAZE_H
#define MAZE_H
/*
* The allowed directions of travel within the Maze.
*/
enum direction {west, north, south, east};
/*
* Represents a location within the Maze.
*/
struct coordinates
{
int x;
int y;
};
class Maze
{
public:
Maze();
/*
* It allows you to pick a seed for the pseudo-random number
* generator and a size. A small size makes it easier for you
* to see what your program is doing. Every instance with the same
* seed and size is guaranteed to have the same Maze.
*/
Maze(int seed, int size);
Maze(const Maze &);
Maze&operator=(const Maze);
~Maze();
/*
* numberOfPositions() returns a count which will hold the length
* of the maximum possible path through the Maze. It's useful for
* allocating enough characters to contain the successful path
* through the Maze.
*/
int numberOfPositions();
/*
* startingPosition() provides the caller with the coordinates
* of the entry into the Maze.
*/
void startingPosition(struct coordinates &where);
/*
* move() takes a direction of travel and the coordinates from
* which to travel as input. The return value lets the caller
* know whether they were permitted to travel in that direction
* from those coordinates. If true, the coordinates are changed
* to the new location in the Maze. If false, either the given
* coordinates are invalid or travel in the given direction from
* the given coordinates is not allowed. If false, the given
* coordinates is unchanged.
*/
bool move(enum direction whichWay, struct coordinates &where);
/*
* escaped() lets the caller know whether the given location is
* the exit of the Maze.
*/
bool escaped(const struct coordinates &where);
private:
int Seed;
int Size;
struct coordinates start;
int **maze;
char *path;
};
#endif
Maze.cpp:
#include
#include
#include "Maze.h"
using namespace std;
Maze::Maze()
{
cout << " inside the default constructor " << endl;
}
Maze::Maze(int seed, int size)
{
Size = size;
Seed = seed;
}
int Maze::numberOfPositions()
{
coordinates.x=0;
coordinates.y=0;
if ((coordinates.x && coordinates.y) == -1) {
return 0;
}
for (int i=0; i< maze.size(); i++){
if (coordinates.y == 0){
coordinates.y == 1;
}
else {
break;
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 7 images