buenzliai/main/statemachine.cpp
2024-05-17 15:37:03 +02:00

32 lines
No EOL
716 B
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) {
if (newState != currentState) {
delete currentState;
currentState = newState;
}
}
void StateMachine::pickedUp() {
State* newState = currentState->pickedUp();
updateState(newState);
}
void StateMachine::putDown(Station* newStation) {
State* newState = currentState->putDown(newStation);
updateState(newState);
}
void StateMachine::update(Context context) {
State* newState = currentState->update(context);
updateState(newState);
}