I have a while loop in my main gameboard class that should constantly check (until the game finishes) if two counters are on the same y axis.
Here is my while loop:
There will be four of the final if statement (one for each counter) and sameColourOnSpace() ans sameSpace() are methods in each counter class.
while(finished == false) {
if(cr1.sameSpace() == 1) cb1.setLocation(cb1.getX(), 385);
if(cr2.sameSpace() == 2) cb2.setLocation(cb2.getX(), 385);
if(cb1.sameSpace() == 1) cr1.setLocation(cb1.getX(), 385);
if(cb2.sameSpace() == 2) cr2.setLocation(cb2.getX(), 385);
if(cr1.sameColourOnSpace() == true)
{
System.out.println("Hello12349999");
cr1.setLocation(cr1.getX(), cr1.yPos);
cr1.act();
}
}public int sameSpace() {
Actor cb1OnSpace = getOneObjectAtOffset(100, 0, CB1.class);
Actor cb2OnSpace = getOneObjectAtOffset(140, 0, CB1.class);
Actor cb12OnSpace = getOneObjectAtOffset(50, 0, CB1.class);
Actor cb22OnSpace = getOneObjectAtOffset(50,0, CB1.class);
if (getY() != 385 && getY() != 237 && getY() != 12) {
if (cb1OnSpace != null || cb12OnSpace != null) return 1;
if (cb2OnSpace != null || cb22OnSpace != null) return 2;
}
return 0;
}public boolean sameColourOnSpace() {
Actor otherCounterOnSpace = getOneObjectAtOffset(50, 0, CR1.class);
Actor otherOtherCounterOnSpace = getOneObjectAtOffset(-50, 0, CR1.class);
if ((otherCounterOnSpace != null || otherOtherCounterOnSpace != null) && getY() != 385 && getY() > 12 && getY() != 237)
{
return true;
}
else {
return false;
}
}
