@Override public void init(GameContainer gc) throws SlickException { gc.setShowFPS(true); this.runwayX = -70; this.runwayY = 298; this.landingX = app.getWidth() - 400; this.landingY = 80; this.takeoffX = app.getWidth() - 400; this.takeoffY = 298; this.airplaneImage = new Image("lab4_AirportSimulation/images/plane.png"); this.backgroundImage = new Image("lab4_AirportSimulation/images/background.png"); }
private void runSimulation() { System.out.println("Update: " + currentUpdate); currentUpdate++; Airplane airplaneHandle; // Randomly add planes for (int i = 0; i < 2; i++) { if (newLandingProbability >= Math.pow(rand.nextDouble(), i)) { airplaneHandle = new Airplane( generateAirplaneNumber(), app.getWidth(), landingY, landingX, landingY, 30 * (simulationDelay / 1000.0)); airQueue.add(airplaneHandle); System.out.println("Now queued for landing: " + airplaneHandle); } } if (newTakeoffProbability >= rand.nextDouble()) { airplaneHandle = new Airplane( generateAirplaneNumber(), app.getWidth(), takeoffY, takeoffX, takeoffY, 30 * (simulationDelay / 1000.0)); groundQueue.add(airplaneHandle); System.out.println("Now queued for takeoff: " + airplaneHandle); } // Load the runway if (runway.isVacant()) if (!airQueue.isEmpty()) { runway.setOccupied(airQueue.poll(), true); runway.getCurrentAirplane().setDestPos(runwayX, runwayY); System.out.println("Now landing: " + runway.getCurrentAirplane()); } else if (!groundQueue.isEmpty()) { runway.setOccupied(groundQueue.poll(), false); runway.getCurrentAirplane().setDestPos(runwayX, runwayY); System.out.println("Now taking off: " + runway.getCurrentAirplane()); } // Set queued airplane destinations Iterator<Airplane> it; it = airQueue.iterator(); int i = 0; while (it.hasNext()) { airplaneHandle = it.next(); airplaneHandle.setDestPos(landingX + (airplaneImage.getWidth() + 10) * i, landingY); i++; } it = groundQueue.iterator(); i = 0; while (it.hasNext()) { airplaneHandle = it.next(); airplaneHandle.setDestPos(takeoffX + (airplaneImage.getWidth() + 10) * i, takeoffY); i++; } // Output information about the runway System.out.println( runway + "\nNumber of planes waiting to land: " + airQueue.size() + "\nNumber of planes waiting to take off: " + groundQueue.size()); // Tick runway runway.tick(); System.out.println(); }