Created
August 5, 2014 12:40
-
-
Save xdegtyarev/f74fba5be2dd07be1364 to your computer and use it in GitHub Desktop.
FSM Example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum State { | |
CHARGING, | |
SEARCH_HUMANS, | |
KILL_ALL_HUMANS | |
} | |
State myState = State.CHARGING; | |
float charge = 0f; | |
void Update() { | |
switch ( myState ) { | |
case State.CHARGING: | |
if ( charge == 100f ) { | |
myState = State.SEARCH_HUMANS | |
} else { | |
DoCharge(); | |
} | |
break; | |
case State.SEARCH_HUMANS: | |
if ( isHumansDetected() ) { | |
myState = State.KILL_ALL_HUMANS | |
} else { | |
SearchHumans(); | |
} | |
break; | |
case State.KILL_ALL_HUMANS: | |
if ( allHumansIsDead() ) { | |
myState = State.CHARGING; | |
} else { | |
KillHumans(); | |
} | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment