klips/cpp/patterns/state/state.cpp

14 lines
479 B
C++
Raw Permalink Normal View History

2021-05-11 22:53:16 +00:00
#include "state.hpp"
// Delegate calls from State->changeState to Car->changeState
void State::changeState(Car *c, State *s) { c->changeState(s);}
// Stopped state transitions
void Stopped::Start(Car *c) { changeState(c, Running::instance());}
void Stopped::Smash(Car *c) { changeState(c, Broken::instance());}
// Running state transitions
void Running::Stop(Car *c) { changeState(c, Stopped::instance());}
void Running::Smash(Car *c) { changeState(c, Burning::instance());}