My teacher wrote this code.
i am having trouble understanding what is going on in the code.
can someone please help me by commenting in the program
if you can tell me the importance of the functions and how everything works.
please help me.... i'm a noob programmer
#include <iostream>
using namespace std;
int col = 0;
int row = 1;
const int ROWMAX = 12;
const int COLMAX = 12;
char maze[ROWMAX][COLMAX] =
{
{'#','#','#','#','#','#','#','#','#','#','#','#'},
{'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#'},
{' ',' ','#',' ','#',' ','#','#','#','#',' ','#'},
{'#','#','#',' ','#',' ',' ',' ',' ','#',' ','#'},
{'#',' ',' ',' ',' ','#','#','#',' ','#',' ',' '},
{'#','#','#','#',' ','#',' ','#',' ','#',' ','#'},
{'#',' ',' ','#',' ','#',' ','#',' ','#',' ','#'},
{'#','#',' ','#',' ','#',' ','#',' ','#',' ','#'},
{'#',' ',' ',' ',' ',' ',' ',' ',' ','#',' ','#'},
{'#','#','#','#','#','#',' ','#','#','#',' ','#'},
{'#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#'},
{'#','#','#','#','#','#','#','#','#','#','#','#'}
};
void printMaze();
void mazeTraverse(int, int);
void printMaze()
{
for(int row = 0; row < ROWMAX; row++)
{
for(int col=0; col < COLMAX; col++)
cout << maze[row][col];
cout << "\n";
}
}
void mazeTraverse(int row, int col)
{
if( (row>0 && row<ROWMAX) && (col>=0 && col<COLMAX)) {
if( maze[row][col] == ' ') {
maze[row][col]='*';
mazeTraverse(row, col+1);
mazeTraverse(row, col-1);
mazeTraverse(row-1, col);
mazeTraverse(row+1, col);
}
}
}
int main()
{
cout << "Maze before solution:\n";
printMaze();
cout << "Maze after solution:\n";
mazeTraverse(1, 2);
printMaze();
return 0;
}