Elevator.cpp in MyElevator.rar
Sponsored links
#include "stdafx.h"
#include "Elevator.h"
CElevator::CElevator()
{
m_iFloor = 1;
m_iHeight = 0;
m_iLoadNum = 0;
m_StepList.clear();
m_Status = WAIT;
}
CElevator::~CElevator()
{
}
void CElevator::DropAndLoad(UINT Floor , UINT& in , UINT & out)
{
m_iLoadNum += (in - out);
////////////////////////
}
float CElevator::GetWaitTime(CStop stop1 , CStop stop2)
{
if (m_StepList.empty())
{
return abs(m_iHeight - (stop1.GetFloor() - 1)*10) * 2.0 /10.0;
}
else
{
float ftime = 0.0;
bool bContinue = true;
list<CStep>::iterator pos = m_StepList.begin();
for( ; pos != m_StepList.end() ; ++pos)
{
if ((*pos).CanLoad(stop1, stop2))
{
ftime += (*pos).GetPartTime(stop1 , m_iHeight);
bContinue = false;
break;
}
}
if (bContinue)
{
list<CStep>::iterator pos1 = m_StepList.end();
--pos1;
CStop stop3 ;
if (UP == (*pos1).GetStatus())
{
(*pos1).GetHStop(stop3);
}
else
{
(*pos1).GetLStop(stop3);
}
ftime += abs(stop1.GetFloor() - stop3.GetFloor()) * 2.0;
}
return ftime;
}
}
void CElevator::InsertStop(_STATUS status , CStop stop1 , CStop stop2)
{
if (m_StepList.empty())
{
float floor = GetFloor(); //
if (floor == (float)(stop1.GetFloor()))//不用空载跑 //
{
CStep step;
step.m_StopVector[stop1.GetFloor()-1] = stop1;
step.m_StopVector[stop2.GetFloor()-1] = stop2;
step.SetStatus(stop1.GetFloor() < stop2.GetFloor() ? UP : DOWN);
m_StepList.push_back(step);
SetStatus( stop1.GetFloor() < stop2.GetFloor() ? UP : DOWN);
}
else//有空载跑
{
if (stop1.GetFloor() < stop2.GetFloor())//UP
{
if (floor < stop1.GetFloor()) //
{
if(floor != (int)floor) //
{
if (UP == status)
{
floor = (int)floor + 1;
}
else
{
floor = (int)floor;
}
}
CStep step;
step.m_StopVector[(int)floor - 1] = CStop((int)floor , 0 , 0);
step.m_Sto
...
...
... to be continued.
This is a preview. To get the complete source file,
please click here to download the whole source code package.