Hi all!
The past couple times I posted they were all about 2D arrays.. and here I am again with them =( I cannot escape them!
Anyway, the project I'm working on requires a Maze class that holds a 2D array and different types of robots that will find their way through the maze.
Main problem: I just want to copy the 2D array inside Maze class to the 2D array inside Robot class. My biggest trouble is accessing where the robot is (orientation) on the maze. And since the maze itself (inside the Maze class) is a private variable, I cannot seem to access the values of the array itself.
Example:
Below is just a quick written summary of what I have so you can see what I'm tying to do.
public class Maze{
private String[][] maze;
private int startX, startY; //declares where the starting point is to place the robot!
public Maze(){ // fill maze array with "|"}
public String[][] getMaze(){ return maze; }
//get/set startX/startY functions();
}
public class Robot{
private int x,y;
private (enum) Orientation; //tells whether the robot's right hand is facing left, right, up, or down on the maze...
private String[][] newMaze;
public Robot(Maze m){
x = m.getStartX();
y = m.getStartY();
newMaze = m.getMaze() //This returns an address - need values to copy to this array!
}
public void move(){
//test where the robot is and what is around him in the variable newMaze.
}
}
This code isn't very pretty but I think it gets the point across. In C++ you can dereference array's to get their values, but I don't know how this would work in Java. There may even be a better way to test where the robot is on the maze, but I'm not sure how.. any ideas on how to fix this?
Thanks in advance!