I'm trying to figure out the basics in state design. I don't quite get it.
Say I have an enum GameState{ MAIN, ABOUT, ADVENTURE, QUIT}, how do I proceed from there?

class Game{
    class state *current;
        void setState(State *){
            current = s;
        void Main();
        void Adventure();
        void About();
        void Quit;

class State{
        virtual void main(Game *g){
            //in main;
        virtual void adventure(Game *g){
            //playing adventure
        virtual void about(Game *g){
            //in About 
        virtual void quit(Game *g){
            //quit game when in this state

void Game::Main(){

void Game::About(){

//the rest of game functions.. Game::Adventure(), Game::Quit().

class Adventure: public State{
        quit(Game *g);
        main(Game *g);

//the rest of the class will be basically the same...

As you can see.. I didn't impement the enum GameState, how can I implement GameState? Should I? I was told that using enum is the way when dealing with state design. the code snipet is what I currently have in mind.

state -> event -> transition -> new state. This is the short version of how FSM (Finite State Machines) work. The system starts in some state, gets an event, evaluates what state to transition to, possibly doing some work during the transition.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.