Hello everybody! I'm new to this forum and also not very experienced in Java. I follow it as a course in my study!
I'm currently working on a assignment wich is to create an ecosystem.
I need a method that moves my objects to a random empty(null) space in a two dimensional array(wich is the grid).
This is what I came up with, at the moment I let it print out the x and y step for testing purposes. It only needs to return an int[] with the x and y direction step. The argument it gets is a 3x3 grid containing an object form my IDier class in the middle. I let a for loop find al objects in the grid and put them into the move method. However it doesn't returns something for every object. Why is this?
public int[] loop(IDier[][] omgeving){ boolean dierGeplaatst=false; Random generator = new Random(); int x= generator.nextInt(3)-1; int y= generator.nextInt(3)-1; int[] richting={0,0}; if(dierGeplaatst==false){ if(omgeving[1+x][1+y] == null){ System.out.println(x+","+y); richting[0]=x; richting[1]=y; dierGeplaatst=true; } else{ dierGeplaatst= false; }} return richting; }
Thanks in advance!