-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElevatorThread.cpp
54 lines (44 loc) · 1.06 KB
/
ElevatorThread.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
#include "mainwindow.h"
Elevator::Elevator()
{
//实例化楼层数组
floor = new floor[5];
}
//电梯开门时
void ElevatorThread::openDoor()
{
//当前时间加上电梯的开门时间
v_time->pass(elevator.doorTime);
//唤醒要在本层上或者下电梯乘客
elevatorArrived.wakeAll();
}
void ElevatorThread::run()
{
while(IsRunning == true)
{
//巡检所有楼层
for(int i = 0; i<MAX_FLOOR;i++)
{
if(Floor[i].signal == true && Floor[i].longestWaitTime>MaxlongestWaitTime)
{
judge = true;
MaxlongestWaitTime = Floor[i].longestWaitTime;
elevator.maxFloor = i;
}
}
while(elevator.atFloor != elevator.maxFloor)
{
if(elevator.atFloor<elevator.maxFloor)
{
up = true;
elevator.run();
}
if(elevator.atFloor>elevator.maxFloor)
{
up = false;
elevator.run();
}
}
openDoor();
}
}