FSMs are very common in games. As I mentioned before, PAC-MAN was an early game that had an AI with more than one state. The ghosts could be in a hunt or a flee state based on a global condition flipped when PAC-MAN would eat a large dot on the screen, commonly known as a power pellet. A specific state in an FSM can be either a global condition or, in the case of a finite state automaton, could be a state that is specific to any autonomous agent within the game. Managing behaviors or state transitions could be as simple as using a switch statement, or they could be more complicated systems that load and unload AI modules when different states are triggered. A state may choose when a transition to a different state occurs, or state transitions could be managed by the game from the top down.
The FSM we will be writing for this game will be very basic. It will be...