}
}
}
//判断是否结束仿真
for(i=1;i<=this->n;i++)
{ if (this->m_passenger.bStart ==true)
flag1=1; }
if (flag1==0) //结束仿真
{ KillTimer(1);
this->m_elevator.bStart =false;
return;
}
//防止没有乘客发信号,系统进入死循环
for(i=1;i<=this->n;i++)
{ if (this->m_passenger.bInLift ==false && this->m_elevator.bStop ==true && this->m_elevator.bStart ==true)
{ this->m_passenger.bSignal =true; //应该是随机
break;
}
}
}
else {
KillTimer(1); //如果电梯运行标志为false,则停止仿真
}
dwTime=::GetTickCount() -this->ElapseTime ;
dwTime=dwTime/1000;
sen.Format("%d",dwTime%60);
h.Format("%d",dwTime/3600);
m.Format("%d",(dwTime/60)%60);
showtime=h+" : "+m+" : "+sen;
this->SetDlgItemText(IDC_STATIC16,showtime);
}
else if (nIDEvent==4) //电梯空载运行(去接乘客)
{ if (this->iEmptySrcFloor ==this->iEmptyDesFloor ) //到达目的地了
{ if (this->iEmptySrcFloor !=1 && this->iEmptySrcFloor !=10 )
{
this->DrawColor(iEmptySrcFloor,1);
this->DrawColor(iEmptySrcFloor,-1);
}
//因为到站了,所以要把电梯设置为接收信号状态
this->m_elevator.bStop =true; //电梯不运行了
this->m_elevator.bIsEmptyOperation =false; //为满载作准备
this->m_elevator.iAtFloor =this->m_elevator.iToFloor ;
this->m_elevator.iToFloor=this->m_elevator.m_passengers[0].iToFloor;
KillTimer(4);
this->itimes[4]=0;
this->iSrcFloor =this->m_elevator.iAtFloor;
this->iDesFloor =this->m_elevator.iToFloor ;
this->m_elevator.bStop =false; //电梯启动
this->itimes[2]++;
if (this->itimes[2]==1)
SetTimer(2,2000 ,0); //启动乘客上电梯 }
if (iEmptySrcFloor <iEmptyDesFloor)
{ this->DrawColor(iEmptySrcFloor,1);
iEmptySrcFloor++; }
else {
this->DrawColor(iEmptySrcFloor,-1);
iEmptySrcFloor--;
}
}
else if(nIDEvent==2) //电梯每隔3秒,电梯是载客运行,还有一种情况是无客运行
{if (iSrcFloor <iDesFloor)
{ this->DrawColor(iSrcFloor,1);
iSrcFloor++; }
else if (iSrcFloor >iDesFloor)
{
this->DrawColor(iSrcFloor,-1);
iSrcFloor--;
}
if (iSrcFloor ==iDesFloor) //到达目的地了
{ this->DrawColor(iSrcFloor,1);
this->DrawColor(iSrcFloor,-1);
//因为到站了,所以要把电梯设置为接收信号状态
this->m_elevator.bStop =true;
this->m_elevator.iAtFloor =this->m_elevator.iToFloor ;
//进行卸载乘客得操作
srand(::GetTickCount());
a =rand()%10+1; //产生一个1到10得随机数
this->m_elevator.m_passengers[0].iAtFloor =this->m_elevator.m_passengers[0].iToFloor ;
this->m_elevator.m_passengers[0].iToFloor = a; //该乘客要去得层数
this->m_elevator.m_passengers[0].iLifts++;
if (this->m_elevator.m_passengers[0].iLifts ==this->l )
this->m_elevator.m_passengers[0].bStart =false;
this->m_elevator.m_passengers[0].bInLift =false; //电梯外面了
this->m_elevator.m_passengers.RemoveAll();
this->m_elevator.iPassengers --;
//为下一次空载作准备
this->m_elevator.bStop =true;
this->m_elevator.bIsEmptyOperation =true;
KillTimer(2);
this->itimes[2]=0; } }
CFormView::OnTimer(nIDEvent);
}
四.结论:
至此,全部的设计过程完毕,上面所有代码已经在
VC6.0+Win2000平台下调试成功。从上面的分析可以看出,实际上运用OOP的思想进行设计的时候,关键是类设计,类设计一定要通过对系统对象域的划分来进行,而关于类里面的具体成员就必须由系统各个部分的功能来进行确定了。总之,类设计不是一天两天的功夫,需要长期的实践才可能达到熟练的程度。