I’m having trouble creating a method which loops through an ArrayList of multiple types of objects.
Here’s my failed attempt:
import java.util.ArrayList;
public class DebugObjects {
public enum Block {
Solid, Bad, Bounce
}
public static void debug(ArrayList<Block> list) {
for (Block b : list) {
String n = b.getClass().getName();
byte i = (byte) Solid.list.indexOf(b);
if (b.X < 0) {
System.out.println(n + " " + i + " is outside the left side.");
}
if (b.X + b.W > Game.WH) {
System.out.println(n + " " + i + " is outside the right side.");
}
if (b.Y < 0) {
System.out.println(n + " " + i + " is outside the up side.");
}
if (b.Y + b.H > Game.WH) {
System.out.println(n + " " + i + " is outside the down side.");
}
}
}
}
My goal with this is to be able to call the method like this:
DebugObjects.debug(Solid.list);
This would loop through all Solid objects inside of Solid.list and tell me if any of them exceed the game window.
Thanks in advance!