I need to clone a 2d array of Cell objects but it doesn't work as it should. Whenever i clone the maze, it clones it but when i make changes to one, it is also visible on the other
somebody knows what the problem is???
public void cloneMaze(boolean backup)
{
if (backup) {
backupMaze = (Cell[][]) maze.clone();
for (int i = 0; i < maze.length; i++) {
backupMaze[i] = (Cell[]) maze[i].clone();
}
} else {
maze = (Cell[][]) backupMaze.clone();
for (int i = 0; i < backupMaze.length; i++) {
maze[i] = (Cell[]) backupMaze[i].clone();
}
}
}