-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelevator.cpp.autosave
76 lines (64 loc) · 1.41 KB
/
elevator.cpp.autosave
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "mainwindow.h"
#include<QTime>
#define MAX_PEOPLE_NUMBER 10;
#define DOOR_ENERGY 1;
#define FLOOR_UP_ENERGY 20;
#define FLOOR_DOWN_ENERGY 10;
#define DOOR_TIME 5;
#define FLOOR_TIME 3;
Elevator::Elevator()
{
status = STOP;
isEmpty = true;
isRunning = false;
maxPeopleNumber = MAX_PEOPLE_NUMBER;
peopleNumber = 0;
//随机生成电梯的初始停靠楼层
//srand((unsigned)time(0));
curFloor = rand()%5 + 1;
doorEnergy = DOOR_ENERGY;
floorUpEnergy = FLOOR_UP_ENERGY;
floorDownEnergy = FLOOR_DOWN_ENERGY;
people = NULL;
doorTime = DOOR_TIME;
//floorTime = FLOOR_TIME;
//楼层
// floor = new Floor[5];
}
int Elevator::searchMaxTime(int& nextFloor,Floor* floor, VTime& t)
{
int maxTime = 0;
nextFloor = 0;
int temp = 0;
for(int i = 0; i < 5; i++)
{
floor[i].searchMaxTime(temp, t);
if(maxTime < temp)
{
maxTime = temp;
nextFloor = i + 1;
}
}
return maxTime;
}
void Elevator::stay()
{
this->status = STOP;
}
void Elevator::run(Floor* floor,VTime& t)
{
searchMaxTime(this->nextFloor, floor, t);
this->status = STOP;
if(this->nextFloor < curFloor)
this->status = DOWN;
else{
if(this->nextFloor > curFloor)
this->status = UP;
//else
// this->up = ;
}
}
int Elevator::GetCurFloor()
{
return curFloor;
}