This commit is contained in:
odonadio 2019-10-19 18:38:38 +02:00
commit 9b42c0f1c1
2 changed files with 9 additions and 55 deletions

View File

@ -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;
}

View File

@ -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() {