-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliftState.cpp
60 lines (47 loc) · 1.19 KB
/
liftState.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "liftState.h"
LiftState::LiftState(unsigned int liftId, unsigned int capacity) {
this->liftId = liftId;
movingDirection = NOT_MOVING;
totalCapacity = capacity;
peopleToGetOff = peopleRemaining = currentFloor = 0;
}
int LiftState::getMovingDelta() {
return (int)movingDirection;
}
bool LiftState::isFull() {
return totalCapacity <= peopleRemaining;
}
bool LiftState::isEmpty() {
return peopleRemaining <= 0;
}
bool LiftState::isMoving() {
return movingDirection != NOT_MOVING;
}
void LiftState::startMoving(MovingDirection direction) {
movingDirection = direction;
}
bool LiftState::hasPeopleToGetOff() {
return peopleToGetOff > 0;
}
unsigned int LiftState::getPeopleToGetOff() {
return peopleToGetOff;
}
unsigned int LiftState::getAvailableSpace() {
return totalCapacity - peopleRemaining;
}
unsigned int LiftState::getLiftId() {
return liftId;
}
unsigned int LiftState::getCurrentFloor() {
return currentFloor;
}
MovingDirection LiftState::getMovingDirection() {
return movingDirection;
}
bool LiftState::goingTo(unsigned int floor) {
switch(movingDirection) {
case UP: return floor > currentFloor;
case DOWN: return floor < currentFloor;
default: return false;
}
}