buenzliai/main/statemachine.cpp

31 lines
673 B
C++
Raw Normal View History

2024-05-17 13:04:36 +00:00
#include "statemachine.h"
#include "station.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() {
State* newState = currentState->update();
updateState(newState);
}