I have an issue with the ACM library. I am trying to create a game. In order to get the applet running in acm you need to make use of the run() method of a graphicsProgram class.
I have a separate class, which has this graphics program as a global field, adding and removing elemnts from the graphical interface. My problem is that if I have a while loop inside this class, the graphics program stops working properly (cannot remove elements, cannot access it from an outside menu...).
Is there any acm expert that knows how to have infinitely many iterations of a while loop together with a working graphicsProgram?
I have:
public class Controller extends GraphicsProgram{
private Battle battle = new Battle();
// Main Loop for the application
public void run() {
battle.startBattle()
}
public class Battle {
private Set<Bullet> bullets = new HashSet<>();
private Set<Platform> platform= new HashSet<>();
private Controller controller;
public Battle(Controller controller) {...}
public void startBattle() {
while (!isGameOver()) {
for (Bullet b: bullets) {
for (Platform p: platforms) {
if (b.intersects(p)) {
controller.remove(b);
} else {
b.move();
}
}
}
I cannot move the code from Battle into Controller because Controller is more complex than the code given.