I need to figure out the solution on my own because this is a project, but can somebody please help me figure out why this if statement isn't working?
myWorld class
sorting bar class
public class MyWorld extends World
{
List<Integer> xloclist = new ArrayList<Integer>();
List<Integer> blockheightlist = new ArrayList<Integer>();
private int calls = 0;
//there is a filereader in between that loads integers into xloclist, but I omitted it here to save space
public int xloc0(){
return xloclist.get(0);
}
public int xlocmin(){
return xloclist.get(Collections.min(xloclist));
}
//returns the current call count
public int globalcalls(){
return calls;
}
public int globalcallsup(){
calls++;
return calls;
}
public int globalcallreset(){
calls = 0;
return calls;
}
}public class SortingBar extends Actor
{
private int calls = 0; //initialize call to act counter
MyWorld myWorld = (MyWorld) getWorld(); //instantiate the world locally for easier access
public void act(){
//if n key is down and calls is 0 or over 25, then...
if(Greenfoot.isKeyDown("n") && calls == 0 || Greenfoot.isKeyDown("n") && calls >25){
//if this x location is 0 or if it is equal to the x location of the shortest block then...
if(this.getX() == myWorld.xloc0() || this.getX() == myWorld.xlocmin()){ //this line is the problem child
//turn the two boxes green.
this.highlight();
}
//increment the call counters in the world and locally
for(int i=0;i<25;i++){
myWorld.globalcallsup(); //increment global call count
calls++;//increment local call count
System.out.println(myWorld.globalcalls()); //print out global call count(for debug)
}
myWorld.globalcallreset(); //reset the global call counter
calls = 0; //reset the local call counter
}
}
}
