new to building finite-state machines. Where do I begin?

Hi,
I have been reading the tutorials and it shows how easy C++ really is. What I still haven't reached yet is how to make finite-state machines. I doubt that is covered and I really need to know how to do that. I have a game that is almost finished it just needs a replay button and a start menu would be nice too. I was told that is all done with finite-state machines. I am using a SDK for programmers to make iPhone apps in C++ and have them work on iPhones without jailbreaking and without owning a Macintosh.
FSMs lend themselves very nicely to implementation in C++. If you understand state machines, then you know that they can be represented as a table of tuples { state, event, action, next_state } where state, event and action are distinct enum types. The context of the class instance is the current state. When an event occurs, a method is called which looks up the { current-state, event } pair. That determines the action to be executed and sets the current state of the instance to the next_state value.

FSMs are also nicely suited to implemention as a template <ST, AT, ET> where ST, AT, and ET are the typenames of the state, event and action enums respectively. This makes it easy to implement different state machines in the same program.
Topic archived. No new replies allowed.