public class Portal extends Slot
Portal represents the places, also known as Slots
where entrances of Tunnels can be opened. It has a Slot connected
to it that is always active, another one that is active if the Portal isn't open,
and a Rail that is active if it is open, which leads into the Tunnel.| Constructor and Description |
|---|
Portal()
Creates a
Portal without any Slots connected to it. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the
Portal by setting the reference to the first Rail
in the Tunnel to null. |
Slot |
getFixSlot()
Returns the reference to the attribute
fixSlot. |
Slot |
getNextSlot(Slot previousSlot)
Returns the
Slot a Vehicle standing on this Portal must move to after its
next step determined by previousSlot. |
boolean |
hasOptionalRoute() |
boolean |
isOpen() |
void |
open(Rail startRailInTunnel)
Opens the
Portal by setting the reference to the first Rail
in the Tunnel to the Rail given by startRailInTunnel. |
void |
setFixSlot(Slot fixSlot)
Sets the
fixSlot of this Portal to the given Slot. |
void |
setOptionalRoute(Slot optionalRoute)
Sets the
optionalRoute of this Portal to the given Slot. |
acquire, addStation, arrive, checkCollision, depart, getStation, getVehicle, isAcquired, releasepublic Slot getNextSlot(Slot previousSlot)
Slot a Vehicle standing on this Portal must move to after its
next step determined by previousSlot.
If the Vehicle came from the fixSlot and there is a startRailInTunnel,
it moves onto it, otherwise it moves onto the optionalRoute.
If the Vehicle came from any other direction, it moves onto the fixSlot.getNextSlot in class SlotpreviousSlot - Slot that determines the direction of movementSlot to move topublic Slot getFixSlot()
fixSlot.fixSlot of this Portalpublic void setFixSlot(Slot fixSlot)
fixSlot of this Portal to the given Slot.fixSlot - the Slot to be set as this Portal's fixRoutepublic void setOptionalRoute(Slot optionalRoute)
optionalRoute of this Portal to the given Slot.optionalRoute - the Slot to be set as this Portal's optionalRoutepublic void open(Rail startRailInTunnel)
Portal by setting the reference to the first Rail
in the Tunnel to the Rail given by startRailInTunnel.startRailInTunnel - the Rail of the Tunnel to be openedpublic void close()
Portal by setting the reference to the first Rail
in the Tunnel to null.public boolean isOpen()
public boolean hasOptionalRoute()