From b6711dd7bc45382dfc9f74b23f40399486ac88a6 Mon Sep 17 00:00:00 2001 From: papush! Date: Sat, 19 Oct 2019 17:49:36 +0200 Subject: [PATCH] handle emergency and cancelling emergency --- src/simulation/Elevator.java | 59 ++++------------------------------ src/simulation/Simulation.java | 5 +-- 2 files changed, 9 insertions(+), 55 deletions(-) diff --git a/src/simulation/Elevator.java b/src/simulation/Elevator.java index 81dde43..4c6de7d 100644 --- a/src/simulation/Elevator.java +++ b/src/simulation/Elevator.java @@ -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; } diff --git a/src/simulation/Simulation.java b/src/simulation/Simulation.java index 79e0725..58d0b34 100644 --- a/src/simulation/Simulation.java +++ b/src/simulation/Simulation.java @@ -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() {