Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Задача Майхилла о стрелках / Examples / VC60 / Стрелки Майхилла / Riflemans / FClasses / Shot / ChainShot
.cpp// ChainShot.cpp: implementation of the CChainShot class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ChainShot.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CChainShot::CChainShot(TNetFsa *pNetFsa)
{
pCOfficer = new COfficer(pNetFsa); // создать офицера
for (int i=1; i<=6; i++) {
IArrayRifleman.push_back(new CRifleman(i,pNetFsa));// создать стрелка
}
SetLink(); // создать связи между объектами
}
CChainShot::~CChainShot()
{
if (pCOfficer) delete pCOfficer;
TIIteratorRifleman iterRifleman = IArrayRifleman.begin();
while (iterRifleman != IArrayRifleman.end()) delete *iterRifleman++;
IArrayRifleman.erase(IArrayRifleman.begin(), IArrayRifleman.end());
}
void CChainShot::SetCommand()
{
if (pCOfficer) pCOfficer->SetCommand();
}
CRifleman* CChainShot::GetAddrRifleman(int n)
{
CRifleman* currentRifleman=NULL;
CRifleman vs(n, NULL);
TIIteratorRifleman iterRifleman = IArrayRifleman.begin();
while (iterRifleman != IArrayRifleman.end()) {
currentRifleman= *iterRifleman++;
if (*currentRifleman==vs) break;
}
return currentRifleman;
}
void CChainShot::SetLink()
{
LFsaAppl *currentRifleman;
TIIteratorRifleman iterRifleman = IArrayRifleman.begin();
int n =1;
LFsaAppl *pFsaLeft = NULL;
LFsaAppl *pFsaRight = NULL;
while (iterRifleman != IArrayRifleman.end())
{
if (n==1)
{
currentRifleman= *iterRifleman++;
((CRifleman*)currentRifleman)->SetNumber(n);
n++;
pFsaLeft = pCOfficer;
pCOfficer->pFsaRightMan = currentRifleman;
pFsaRight= *iterRifleman++;
((CRifleman*)pFsaRight)->SetNumber(n);
n++;
((CRifleman*)currentRifleman)->SetLink(pFsaLeft, pFsaRight);
}
else
{
pFsaLeft = currentRifleman;
if (iterRifleman != IArrayRifleman.end())
{
currentRifleman = pFsaRight;
pFsaRight= *iterRifleman++;
((CRifleman*)pFsaRight)->SetNumber(n);
n++;
((CRifleman*)currentRifleman)->SetLink(pFsaLeft, pFsaRight);
}
}
}
pFsaLeft = currentRifleman;
currentRifleman = pFsaRight;
pFsaRight= NULL;
((CRifleman*)currentRifleman)->SetLink(pFsaLeft, pFsaRight);
}
Соседние файлы в папке Shot