46 lines
1 KiB
C++
46 lines
1 KiB
C++
#include "statemachine.h"
|
|
#include "station.h"
|
|
#include "context.h"
|
|
|
|
StateMachine::StateMachine(State* initialState)
|
|
: currentState(initialState)
|
|
{
|
|
}
|
|
|
|
StateMachine::~StateMachine()
|
|
{
|
|
delete currentState;
|
|
}
|
|
|
|
void StateMachine::updateState(State* newState, const Context& context)
|
|
{
|
|
if (newState != currentState)
|
|
{
|
|
delete currentState;
|
|
currentState = newState;
|
|
currentState->activated(context);
|
|
}
|
|
}
|
|
|
|
void StateMachine::pickedUp(const Context& context)
|
|
{
|
|
State* newState = currentState->pickedUp(context);
|
|
updateState(newState, context);
|
|
}
|
|
|
|
void StateMachine::putDown(const Context& context, Station* newStation)
|
|
{
|
|
State* newState = currentState->putDown(context, newStation);
|
|
updateState(newState, context);
|
|
}
|
|
|
|
void StateMachine::update(const Context& context)
|
|
{
|
|
State* newState = currentState->update(context);
|
|
updateState(newState, context);
|
|
}
|
|
|
|
String StateMachine::updateDisplay(const Context& context) const
|
|
{
|
|
return currentState->updateDisplay(context);
|
|
}
|