//Bell.h
#ifndef BELL_H
#define BELL_H
class Bell{
public:
void Ring()
{
cout << "电梯铃发出:叮!" << endl;
}
};
#endif //BELL_H
//Building.h
#ifndef BUILDING_H
#define BUILDING_H
#include "Elevator.h"
#include "Floor.h"
#include "ElevatorDoor.h"
class Building {
public:
void PressOutsideButton1(vector<Person>::iterator);
void PressOutsideButton2(vector<Person>::iterator);
protected:
Floor F1;
Floor F2;
Elevator Ele;
ElevatorDoor EleDoor1;
ElevatorDoor EleDoor2;
Button OutsideButton1;
Button OutsideButton2;
void CheckElevatorOutsideButton();
};
inline void Building::PressOutsideButton1(vector<Person>::iterator iter)
{
(*iter).PrintPersonNum();
cout << "按下大楼第1层的电梯外开关,";
if (Ele.State==1) EleDoor1.Open();
else if (Ele.State==2)
{
Ele.Down2to1();
OutsideButton1.LightOn();
}
else OutsideButton1.LightOn();
}
inline void Building::PressOutsideButton2(vector<Person>::iterator iter)
{
(*iter).PrintPersonNum();
cout << "按下大楼第2层的电梯外开关,";
if (Ele.State==2) EleDoor2.Open();
else if (Ele.State==1)
{
Ele.Up1to2();
OutsideButton2.LightOn();
}
else OutsideButton2.LightOn();
}
inline void Building::CheckElevatorOutsideButton()
{
EleDoor1.Close(); //执行电梯关门造作。
EleDoor2.Close();
if (Ele.State==1 ||Ele.State==2)//电梯状态静止
{
if (OutsideButton1.LightState()) //如果1层外的灯还亮着
Ele.Down2to1(); //让电梯从2层去1层
if (OutsideButton2.LightState()) //如果2层外的灯还亮着
Ele.Up1to2(); //让电梯从1层去2层
}
}
#endif // BUILDING_H
//Button.h
#ifndef BUTTON_H
#define BUTTON_H
#include <iostream>
using namespace std;
class Button{
public:
Button():State(0){}
void LightOn();
void LightOff();
bool LightState() {return State;}
private:
bool State; // 0:灭 1:亮
};
inline void Button::LightOn()
{
if (!State)
{
State = 1;
cout << "开关的灯亮了。"<<endl;
}
}
inline void Button::LightOff()
{
if (State)
{
State = 0;
cout << "开关的灯灭了。"<<endl;
}
}
#endif //BUTTON_H
//Elevator.cpp
#include "Elevator.h"
void Elevator::Next()
{
if (LeftTime==0)
{
if (State==12) //到达了2层
{
State=2;
Stop();
if (InsideButton2.LightState())
{
cout << "电梯内";
InsideButton2.LightOff();
}
ElevatorBell.Ring();
}
if (State==21) //到达