in the greep game my problem is more than one greeps stop at tomato although i put in my code
else if (greeps==null) {
move();
}


1 2 3 | if (!getWorld().getObjectsAt(getX(), getY(), Tomato. class ).isEmpty()) { //stop moving because of the tomato; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | if (!getWorld().getObjectsAt(getX(), getY(), Tomato. class ).isEmpty() && !otherGreepAtThisPosition()) { //stop moving because of the tomato and no other greep; } //to use this method you have to import java.util.List; public booleanOtherGreepAtThisPosition() { List<Greep> greeps = getWorld().getObjectsAt(getX(), getY(), Greep. class ); if (!greeps.isEmpty()) { for (Greep greep : greeps) { if (! this .equals(greep)) { return true ; } } } return false ; } |