Step.cpp in MyElevator.rar
Sponsored links
#include "stdafx.h"
#include "Step.h"
bool CStep::GetHStop(CStop& stop)
{
for(int i = 4 ; i >= 0 ; --i)
{
if (m_StopVector[i].m_bAlreadyHaveTask)
{
stop = m_StopVector[i];
return true;
}
}
return false;
}
float CStep::GetPartTime(CStop stop , float fHeight)
{
CStop stop1 , stop2;
float ftime = 0.0;
if (!GetHStop(stop1) || !GetLStop(stop2))
{
return 0.0;
}
if (stop2.GetFloor() == stop1.GetFloor())
{
return 0.0;
}
if (UP == m_status)
{
for(int i = stop2.GetFloor() ; i < fHeight ; ++i)
{
ftime += 2.0;
if (!m_StopVector[i-1].IsEmpty())
{
ftime += 2.0;
}
if (stop.GetFloor() >= i)
{
break;
}
}
ftime += ((int)fHeight - fHeight + 1 )/ 1.4;
return ftime;
}
if (DOWN == m_status)
{
for(int i = stop1.GetFloor() ; i > fHeight ; --i)
{
ftime += 2.0;
if (!m_StopVector[i-1].IsEmpty())
{
ftime += 2.0;
}
if (stop.GetFloor() <= i)
{
break;
}
}
ftime += (fHeight - (int)fHeight)/ 1.4;
return ftime;
}
return 0.0;
}
bool CStep::Empty()
{
for(int i = 0 ; i < 5 ; ++i)
{
if (!m_StopVector[i].IsEmpty())
{
return false;
}
}
return true;
}
bool CStep::CanLoad(CStop stop1 , CStop stop2)
{
if (Empty())
{
return true;
}
else
{
if (stop2.GetFloor() > stop1.GetFloor() && UP == m_status)
{
CStop stop3;
GetLStop(stop3);
if (stop1.GetFloor() >= stop3.GetFloor())
{
return true;
}
}
if (stop2.GetFloor() < stop1.GetFloor() && DOWN == m_status)
{
CStop stop3;
GetHStop(stop3);
if (stop1.GetFloor() <= stop3.GetFloor())
{
return true;
}
}
}
return false;
}
float CStep::GetAllTime()
{
float ftime = 0.0;
CStop stop1 , stop2;
GetHStop(stop2);
GetLStop(stop1);
if (!GetHStop(stop2) || !GetHStop(stop1))
{
return 0.0;
}
for(int i = stop1.GetFloor() ; i < stop2.GetFloor() ; ++i)
{
ftime += 2.0;
if (!m_StopVector[i-1].IsEmpty())
{
ft
...
...
... to be continued.
This is a preview. To get the complete source file,
please click here to download the whole source code package.