
Untitled
By: a guest on
May 9th, 2012 | syntax:
Java | size: 1.37 KB | hits: 18 | expires: Never
public void searchMaze(int r, int c) {
if(mazeArray[currentRow][currentColumn] == exit) {
System.out.printf("The explorer has left the building!\n");
System.exit(0);
}
else if(mazeArray[currentRow - 1][currentColumn] == space || mazeArray[currentRow - 1][currentColumn] == visited) {
mazeArray[currentRow][currentColumn] = visited;
mazeArray[currentRow - 1][currentColumn] = explorer;
currentRow -= 1;
searchMaze(currentRow, currentColumn);
}
else if(mazeArray[currentRow][currentColumn + 1] == space || mazeArray[currentRow][currentColumn + 1] == visited) {
mazeArray[currentRow][currentColumn] = visited;
mazeArray[currentRow][currentColumn + 1] = explorer;
currentColumn += 1;
searchMaze(currentRow, currentColumn);
}
else if(mazeArray[currentRow + 1][currentColumn] == space || mazeArray[currentRow + 1][currentColumn] == visited) {
mazeArray[currentRow][currentColumn] = visited;
mazeArray[currentRow + 1][currentColumn] = explorer;
currentRow += 1;
searchMaze(currentRow, currentColumn);
}
else if(mazeArray[currentRow][currentColumn - 1] == space || mazeArray[currentRow][currentColumn - 1] == visited) {
mazeArray[currentRow][currentColumn] = visited;
mazeArray[currentRow][currentColumn - 1] = explorer;
currentColumn -= 1;
searchMaze(currentRow, currentColumn);
}
}