Hi people,
I'm working on an airport simulation and I need objects of the class Aircraft to interact with each other according to their positions.
What should happen is that aircraft come in for landing (this works and every 10 seconds a new object of Aircraft is being created and lands). At the end of the runway, the aircraft goes to a gate and stops. But now, every object of the class Aircraft goes to the same gate. What I need is to let all aircraft know if there's already another aircraft at a specific gate. If this is the case, the aircraft that has just landed must taxi to another gate.
This is what I have now:
The field public int gatePosition should have a value. When an aircraft is parked at gate number one, this variable gets a value of 1. This also works, but now I need other objects of the class Aircraft to know that another aircraft already has the value of one. When this is the case, the second aircraft should go to the another gate (the method for taxiing to another gate is not a problem, but I need a correct if statement to let another object understand that the previous aircraft is already at gate number one. Inside this if statement, the method for taxiing to another gate will be called.
Who knows how I can do this?
Cheers!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Aircraft here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Aircraft extends Actor
{
public int gatePosition;
/**
* Act - do whatever the Aircraft wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Aircraft()
{
setRotation(-90);
}
public void act()
{
move();
checkPlanePosition();
}
// landing and taxiing to gate number one
public void move()
{
if (getX() == 70 && getY() == 102){
turn(90);
move(2);
}
if (getX() == 694 && getY() == 102){
turn(90);
move(2);
}
if (getX() == 694 && getY() == 444){
move(0);
gatePosition = 1;
}
else{
move(2);
}
}
// check if gate number 1 is full and taxi to another gate if this is the case
public void checkPlanePosition()
{
if (gatePosition != 1 && getX()!= 694 && getY() != 444){
// taxi to another gate if gate number 1 is full
}
}
}
