Picture 1 down below is of a Maze program I wrote as it looks when you open it. Picture 2 is the same Maze after the program finds its way out.
I want to alter the code so the program adds each blue spot one at a time as it works its way through the maze, and if it hits a dead end, to erase each blue dot one at a time as it backs up. The code for the system to find its way through the maze is below. I'm a first year java programmer, so I'm sorry if it's a little unorthodox or anything. For instance, I know this could be a lot shorter. I could rewrite it with fewer if statements and such.
When the code hits square (5,3) I'd like the blue dots to keep going up and search the upper right chamber, and then back up and move on to square (6,3) when it realizes it went into a dead end.
I've tried a few different things with the Sleep() method, but all it seems to do is lengthen the time it takes for the whole maze to update with the blue path straight through.
Thanks for your help.
public void findNext(int x, int y) {
maze[x][y].beenTested = true;
maze[x][y].addSpot();
if(y == 9) {
foundExit = true;
}
if (y > 0) {
if ((maze[x][y-1].isOpen) && !(maze[x+1][y].beenTested) && !(foundExit)) {
findNext(x + 1, y);
}
}
if (x < 9) {
if ((maze[x+1][y].isOpen) && !(maze[x][y+1].beenTested) && !(foundExit)) {
findNext(x, y + 1);
}
}
if (y < 9) {
if ((maze[x][y+1].isOpen) && !(maze[x-1][y].beenTested) && !(foundExit)) {
findNext(x - 1, y);
}
}
if (x > 0) {
if ((maze[x-1][y].isOpen) && !(maze[x][y-1].beenTested) && !(foundExit)) {
findNext(x, y - 1);
}
}
if(!foundExit) {
maze[x][y].removeSpot();
}
}