Hi all,
Basically I am designing a virtual 2Dimensional grid, made up of cells, and an object that will be able to simulate moving from cell to cell.
So far I've got four classes:
1 main
2 GridBot
3 Grid
4 Cell
My question is how do I allow an instance of GridBot to set a variable in an instance of Cell. I have tried objectname.method() but it doesnt work.
I've taken the time to slim down my coding so that you can see more easily what my problem is.
public class main(){
public gridBot aGridBot = new gridBot();
public Grid theGrid = new Grid();
public static void main(String args[]){
main theMainProgram = new main();
}
public main(){
//link gridBot to cell 1,1 and set its occupied state to true
aGridBot = new gridBot();
aGridBot.CellCoordinateX = 1;
aGridBot.CellCoordinateY = 1;
theGrid.setCell(1, 1, true);
}
}
public class Grid{
public Cell aCell[][] = new Cell[4][4];
public Grid(){
this.InitializeCells();
}
public void InitializeCells(){
for (int x=0; x<4; x++){
for (int y = 0; y<4; y++){
aCell[x][y] = new Cell();
}
}
}
public void setCell(int x, int y, boolean YesNoOccupied){
aCell[x][y].Occupied = YesNoOccupied;
}
}
public class Cell{
boolean Occupied;
public Cell(){
Occupied = false;
}
}
public class gridBot{
public int CellCoordinateX;
public int CellCoordinateY;
//this is the method I am trying to develop, currently not called by anything
public void VirtualMove(){
CellCoordinateX = CellCoordinateX + 1;
CellCoordinateY = CellCoordinateY + 1;
//I want to invoke method setCell in 'theGrid'
}
}