Files
makefile_cpp/Make/sudoku/command.cpp
2023-04-13 14:02:08 +08:00

36 lines
752 B
C++

#include "scene.h"
#include "command.h"
CCommand::CCommand(CScene *pOwner) : _pOwner(pOwner)
{}
CCommand::CCommand(CScene *pOwner, const point_t &point, int preValue, int curValue)
: _pOwner(pOwner), _stPoint(point), _nPreValue(preValue), _nCurValue(curValue) {}
CCommand::CCommand(const CCommand &rhs)
: _pOwner(rhs._pOwner)
, _stPoint(rhs._stPoint)
, _nPreValue(rhs._nPreValue)
, _nCurValue(rhs._nCurValue)
{}
CCommand::~CCommand(){}
bool CCommand::execute(int nInputValue)
{
if (!_pOwner)
return false;
_stPoint = _pOwner->getCurPoint();
return _pOwner->setCurValue(nInputValue, _nPreValue);
}
void CCommand::undo()
{
if (_pOwner)
{
_pOwner->setPointValue(_stPoint, _nPreValue);
}
return;
}