Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Задача Майхилла о стрелках / Examples / VC60 / Стрелки Майхилла / Riflemans / FClasses / Shot / Rifleman
.cpp// Rifleman.cpp: implementation of the CRifleman class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Rifleman.h"
#include "LSYSLIB\FDelayCLK.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
extern LArc RiflemanTBL[];
CRifleman::CRifleman():LFsaAppl() { }
CRifleman::CRifleman(int n, TNetFsa *pNetFsa, LArc* pTBL):LFsaAppl(pTBL)
{
pFsaRightMan = NULL;
pFsaLeftMan = NULL;
nNumber = n;
nLengthQueue = 5;
nCurrentQueue = nLengthQueue;
FLoad(pNetFsa,1); // подключить объект к КА-сети
lDelay = 1;
}
CRifleman::~CRifleman() { }
bool CRifleman::operator==(const CRifleman &var) const
{
if (nNumber==var.nNumber) return true;
else return false;
}
void CRifleman::SetLink(LFsaAppl * pFsaLeft, LFsaAppl * pFsaRigtht)
{
pFsaRightMan = pFsaRigtht;
pFsaLeftMan = pFsaLeft;
}
int CRifleman::GetNumber() { return nNumber; }
void CRifleman::SetNumber(int n) { nNumber = n; }
//
LArc RiflemanTBL[] = {
LArc("сон", "огонь", "x1", "y1"),
LArc("огонь", "готов", "x2", "y2"),
LArc("готов", "готов", "x3", "y2"),
LArc("готов", "выстрел", "^x3", "y3y4"),
LArc("выстрел", "выстрел", "x4", "y3y5"),
LArc("выстрел", "сон", "^x4", "--"),
LArc()
};
int CRifleman::x1()
{
if (!pFsaLeftMan) return false;
return string((pFsaLeftMan)->FGetState()) == "огонь";
}
int CRifleman::x2()
{
if (!pFsaRightMan) return true;
else
return string((pFsaRightMan)->FGetState()) == "готов";
}
int CRifleman::x3() { return nNumber; }
int CRifleman::x4() { return nCurrentQueue; }
void CRifleman::y1()
{
int n = ((CRifleman*)pFsaLeftMan)->GetNumber();
SetNumber(n+1);
nSaveNumber = nNumber;
}
void CRifleman::y2() { nNumber--; }
void CRifleman::y3() { }
void CRifleman::y4() { nCurrentQueue = nLengthQueue; }
// формирование задержки между выстрелами
void CRifleman::y5()
{
FDelayCLK *pCFDelay;
pCFDelay = new FDelayCLK(lDelay);
pCFDelay->FCall(this);
nCurrentQueue--;
}
Соседние файлы в папке Shot