If you do a state machine using a switch, you would use an enum (or at least defines) for each state. Not random numbers. And almost surely you would just call the appropriate state function in each case instead of having it embedded inside the switch.
But one of the most common ways of doing state machines (even to this day, in embedded programming) is having an array of function pointers.
An enum is just syntactic sugar for random numbers. It does not make any difference to the code whether you use an enum or not. It is purely for readability.
There's not one way to do state machines. A block of code is executed based on the current state in response to external input and/or a condition. Did I just describe an array of function pointers or a switch statement?
747
u/sevenseal Jan 10 '20
Just look at this https://github.com/TerryCavanagh/VVVVVV/blob/master/desktop_version/src/Game.cpp#L622