Game Development Reference
In-Depth Information
FSM
STATE_B = 1, // a second arbitrary state
STATE_C = 2 // a third arbitrary state,
et cetera
};
Note that we make the enumeration public so that other client classes can
have access (to set the state). Also note that we have four distinct states for
an FSM with three logical states as it is useful to encode an error state in our
type for -1. A variable of type eMyState is declared in the class to store the
current value of the state.
• A switch case block: This structure allows the program to jump to the current
state/block (as indicated from the enumeration) to invoke the code for that
state as shown in the following code:
Switch (state) {
case(eMyState.STATE_A):
{
// code for STATE A here
break;
}
case(eMyState.STATE_B):
{
// code for STATE B here
break;
}
case(eMyState.STATE_C):
{
// code for STATE C here
break;
}
Default:
{
// handle fatal error
Search WWH ::




Custom Search