XFactorDev.net Article   XFactorDev.net Article

 

Prt-3- Let the Games begin..

 

Rome wasn't built in a day they say...well a game engine can't be built in a day either...heheh...well not a super cool, mega fun, brain sizzler one that where going to make ;)  Now our next part is to put the CGame class together and show you its workings....this chapter should be over in a second, as the CGame class is basically our game container class, its job is to initilize everything and check and process our game...then when all is said and done, clean up.

 

 

The code of relevance is as follows:

 

/***************************************************************************/

/*                                                                         */

/*  game.h                                                                 */

/*                                                                         */

/***************************************************************************/

 

#ifndef _XF_GAME_H

#define _XF_GAME_H

 

 

class CGame

{

public:

      // Initilisation called only once in the constructor

      CGame();

 

      // GameLoop, gets called repeatedly while it returns 1;

      bool GameLoop();

 

      // Cleanup process, all done in our destructor

      ~CGame();

};

 

 

#endif // _XF_GAME_H

 

 

 

f

/***************************************************************************/

/*                                                                         */

/*  game.cpp                                                               */

/*                                                                         */

/***************************************************************************/

  

#include "game.h"

 

 

// Initilisation called only once in the constructor

CGame::CGame()

{

}

 

// GameLoop, gets called repeatedly while it returns 1;

bool CGame::GameLoop()

{

 

      // Return 1 for the game to continue, 0 to terminate.

      return 1;

}

 

// Cleanup process, all done in our destructor

CGame::~CGame()

{

}

  

/***************************************************************************/

/*                                                                         */

/* How this all works....well I'm not saying its the best method, maybe    */

/* later if it progresses to a higher level we'll include linked list's    */

/* for cueing of game stages like splash, intro, menu etc.... but all one  */

/* step at a time!  Flexibibity is our aim!                                */

/*                                                                         */

/***************************************************************************/

 

 

 

 

 

And well the only other changes, are in main.h and main.cpp, as we have to mention it and call our wonderful new simple CGame Class......I've outlined the relevant things with //NEW NEW etc**.

 

 

/***************************************************************************/

/*                                                                         */

/*  main.h                                                                 */

/*                                                                         */

/***************************************************************************/

 

#ifndef _XF_MAIN_H

#define _XF_MAIN_H

 

 

void main();

 

//NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW

//NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW

//NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW

 

//-------------------------------------------------------------------------//

//                                                                         //

// Well if we want to use the CGame class we have to tell the main.h       //

// file header....so me put it here                                        //

//                                                                         //

//-------------------------------------------------------------------------//

#include "game.h"

 

 

#endif // _XF_MAIN_H

 

And the .cpp file for our main.h is below:

 

/***************************************************************************/

/*                                                                         */

/*  main.cpp                                                               */

/*                                                                         */

/***************************************************************************/

 

 

#include "main.h"

 

// Lets include our debug!

#include "debug.h"

 

void main()

{

          /*

            -1- Initilize Any Main Functions

            */

            debug("CGame Instance Created, and its constructor called");

            //NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW

            CGame *pGame = new CGame();

           

 

 

            /*

            -2- Go InTo GameLoop

            */

            debug("Going to do a GameLoop");

            //NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW

            while(true)

            {

                  // Continue calling GameLoop until it returns zero.

                  if( pGame->GameLoop() == 0 )

                        break;

            }

           

 

            /*

            -3- Clean Up Anything And Say Goodbye :)

            */

            debug("Washing and doing the dishes (Cleanup)..");

            //NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW

            delete pGame;

}

 

Well its not much...but its a structure, a skeleton...its allowing us all to work from common ground ;)

 

 

 

 

 

 

 

 

 

 

 

 

  XFactorDev.net Article



      
webmaster@xfactordev.net