I am asked to make a maze game in c++ (using codeblocks). I figured out most of it, but stuck in one method of Maze class. I have this function to say that travel in anyone direction (up, down, left, right) where you dont get the wall.
int Maze::mazeTraversal(int a, int b)
{
// If a,b is outside maze, return false.
if ( a < 0 || a > MCOLS - 1 || b < 0 || b > NROWS - 1 ) return FALSE;
// If a,b is the goal, return true.
if ( maze[b][a] == 'G' ) return TRUE;
// If a,b is not open, return false.
if ( maze[b][a] != '0' && maze[b][a] != 'S' ) return FALSE;
// Mark a,b part of solution path.
maze[b][a] = 'x';
// If find_path North of a,b is true, return true.
if ( mazeTraversal(a, b - 1) == TRUE ) return TRUE;
// If find_path East of a,b is true, return true.
if ( mazeTraversal(a + 1, b) == TRUE ) return TRUE;
// If find_path South of a,b is true, return true.
if ( mazeTraversal(a, b + 1) == TRUE ) return TRUE;
// If find_path West of a,b is true, return true.
if ( mazeTraversal(a - 1, b) == TRUE ) return TRUE;
// Unmark a,b as part of solution path.
maze[b][a] = '0';
return FALSE;
}
I am calling this function as:
Maze mo(maze,12); //creating maze game with 12/12 array
mo. mazeTraversal(0,2) // because the entry point is in 0,2 position of the game.
I just realised that I am asked to have this mazeTraversal as void
. No any return. My mind is blowing up. Excepting some creative ideas please.