31 lines
No EOL
673 B
C++
31 lines
No EOL
673 B
C++
#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);
|
|
} |