package class2_2_PinballStrategy_start; import java.util.ArrayList; import java.util.List; /** * This Ball simulation application is going to go viral * @author hornick * copyright, because this will make a boatload of ca$h. */ public class PinballMachine { private static boolean doContinueGame; /** * @param args - not used */ public static void main(String[] args) { doContinueGame = true; TableTop table = new TableTop("Angry angry ducks"); // note catchy name // create some ducks List balls = new ArrayList(); balls.add(new Ball("Daffy")); balls.add(new Ball("Donald")); balls.add(new Ball("Clyde")); // put them on the table for(Ball ball:balls) { table.addBall(ball); } gamePlay(table, balls); } private static void gamePlay(TableTop table, List balls) { // We should really only deal with GUI objects from the "event dispatch thread" // But we haven't talked about threading yet, so please trust us that this works. while(doContinueGame) { // loop forever for(Ball b:balls) { b.move(); } table.repaint(); // update the window display after the balls roll try { Thread.sleep(50); // pause for 50ms } catch(InterruptedException e) { // not used; but required in case something wakes us from our 50ms nap /* yawn */ } } } }