implement slowing down before reaching the target floor
This commit is contained in:
@ -9,7 +9,7 @@ import commandSystem.Direction;
|
||||
class ElevatorCanvas extends JPanel {
|
||||
private final static int WIDTH = 40;
|
||||
private final static int HEIGHT = 50;
|
||||
private final static Dimension DIMENSIONS = new Dimension(WIDTH, 200);
|
||||
private final static Dimension DIMENSIONS = new Dimension(WIDTH, 300);
|
||||
|
||||
private Elevator elevator;
|
||||
|
||||
@ -33,21 +33,26 @@ class ElevatorCanvas extends JPanel {
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (elevator.getStoppingNextFloor()) {
|
||||
if (elevator.getEmergency()) {
|
||||
g.setColor(Color.RED);
|
||||
}
|
||||
else if (elevator.getStoppingNextFloor()) {
|
||||
g.setColor(Color.BLUE);
|
||||
}
|
||||
else if (elevator.getDirection() == Direction.NONE) {
|
||||
g.setColor(Color.GRAY);
|
||||
}
|
||||
else if (elevator.getEmergency()) {
|
||||
g.setColor(Color.RED);
|
||||
g.setColor(Color.GREEN);
|
||||
}
|
||||
else {
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
// g.fillRect(0, 200 - (int) Math.floor(elevator.getHeight() * 200) - HEIGHT, WIDTH, HEIGHT);
|
||||
// System.out.println("elevator height:" + elevator.getHeight());
|
||||
g.fillRect(0, 200 - HEIGHT - (int) ((200 - HEIGHT) * elevator.getHeight()), WIDTH, HEIGHT);
|
||||
g.fillRect(0, (int) DIMENSIONS.getHeight() - HEIGHT - (int) (((int) DIMENSIONS.getHeight() - HEIGHT) * elevator.getHeight()), WIDTH, HEIGHT);
|
||||
|
||||
g.setColor(Color.GRAY);
|
||||
int nbFloors = elevator.getNbFloors();
|
||||
for (int i = 0; i < nbFloors; i++) {
|
||||
int y = i * ((int) DIMENSIONS.getHeight() / (nbFloors - 1));
|
||||
g.fillRect(0, y-1, WIDTH, 3);
|
||||
}
|
||||
|
||||
Toolkit.getDefaultToolkit().sync();
|
||||
}
|
||||
|
Reference in New Issue
Block a user