handle emergency and cancelling emergency
This commit is contained in:
parent
2972cd0e0e
commit
b6711dd7bc
@ -12,8 +12,6 @@ public class Elevator {
|
||||
private double floorHeight;
|
||||
private double step;
|
||||
private double height;
|
||||
// private int currentFloor = 0;
|
||||
// private boolean betweenFloors = false; /* Between currentFloor and the one above it. */
|
||||
private Direction direction = Direction.NONE;
|
||||
private boolean stoppingNextFloor = false;
|
||||
private boolean emergency = false;
|
||||
@ -61,69 +59,24 @@ public class Elevator {
|
||||
|
||||
public void update() {
|
||||
if (emergency) return;
|
||||
// int prevFloor = (int) Math.floor(height / floorHeight);
|
||||
switch (direction) {
|
||||
// case DOWN:
|
||||
// height -= step;
|
||||
|
||||
// /* Bottom reached. */
|
||||
// if (height < step) {
|
||||
// height = 0;
|
||||
// direction = Direction.NONE;
|
||||
// }
|
||||
|
||||
// /* Passed a floor, invoke the listener. */
|
||||
// if (Math.floor(height / floorHeight) < prevFloor && listener != null) {
|
||||
// listener.floorChange(Direction.DOWN);
|
||||
// }
|
||||
// // /* Go halfway below. */
|
||||
// // if (!betweenFloors) currentFloor--;
|
||||
// // betweenFloors = !betweenFloors;
|
||||
// break;
|
||||
// case UP:
|
||||
// height += step;
|
||||
|
||||
// /* Top reached. */
|
||||
// if (height > 1-step) {
|
||||
// height = 1;
|
||||
// direction = Direction.NONE;
|
||||
// }
|
||||
|
||||
// /* Passed a floor, invoke the listener. */
|
||||
// if (Math.floor(height / floorHeight) > prevFloor && listener != null) {
|
||||
// listener.floorChange(Direction.UP);
|
||||
// }
|
||||
// // /* Go halfway above. */
|
||||
// // if (betweenFloors) currentFloor++;
|
||||
// // betweenFloors = !betweenFloors;
|
||||
// break;
|
||||
case DOWN:
|
||||
height -= step;
|
||||
|
||||
if (height % floorHeight < step && listener != null) {
|
||||
listener.floorChange(Direction.DOWN);
|
||||
}
|
||||
break;
|
||||
|
||||
case UP:
|
||||
height += step;
|
||||
if (height % floorHeight < step && listener != null) {
|
||||
listener.floorChange(Direction.UP);
|
||||
}
|
||||
break;
|
||||
case UP:
|
||||
height += step;
|
||||
if (height % floorHeight < step && listener != null) {
|
||||
listener.floorChange(Direction.UP);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// public int getCurrentFloor() {
|
||||
// return currentFloor;
|
||||
// }
|
||||
|
||||
// public boolean getBetweenFloors() {
|
||||
// return betweenFloors;
|
||||
// }
|
||||
|
||||
public Direction getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
@ -46,11 +46,12 @@ public class Simulation implements ElevatorListener {
|
||||
}
|
||||
|
||||
public void emergency() {
|
||||
System.out.println("Emergency declared.");
|
||||
elevator.emergencyStop();
|
||||
}
|
||||
|
||||
public void cancelEmergency() {
|
||||
System.out.println("Emergency cancelled.");
|
||||
queue = new BasicInstructionQueue();
|
||||
elevator.cancelEmergency();
|
||||
}
|
||||
|
||||
private void update() {
|
||||
|
Reference in New Issue
Block a user