Cpp:Building A Simple Tile Engine:Part 7

From GPWiki

Files:GUITutorial_warn.gif The Game Programming Wiki has moved! Files:GUITutorial_warn.gif

The wiki is now hosted by GameDev.NET at wiki.gamedev.net. All gpwiki.org content has been moved to the new server.

However, the GPWiki forums are still active! Come say hello.

Part 7: Creating the game manager


I haven't got the time to finish this article right now, so until I have here's a stub box for you to look at:

This page is far from complete, go ahead and write some more!
You can extend this page by editing it.

File: Game.h

#ifndef GAME_H
#define GAME_H
 
#include "Interfaces.h"
#include "TileManager.h"
#include "UnitManager.h"
 
/** Game class */
class CGame: public IBaseEntity
{
private:
	CTileManager m_oTileManager;
	CUnitManager m_OUnitManager;
 
public:
	CGame();
	virtual ~CGame();
 
	virtual void			VThink		( const int& iElapsedTime );
	virtual void			VRender		( SDL_Surface* pDestSurface	);
 
	virtual bool			VLoad		( TiXmlElement* pXMLData );
	virtual TiXmlElement	VGetSaveData();
 
	CTileManager* GetTileManager() { return &m_oTileManager; }
	CUnitManager* GetUnitManager() { return &m_OUnitManager; }
};
 
#endif // GAME_H 

File: Game.cpp

#include "Game.h"
 
CGame::CGame()
{
 
}
 
CGame::~CGame()
{
 
}
 
void CGame::VThink( const int& iElapsedTime )
{
	m_oTileManager.VThink( iElapsedTime );
	m_OUnitManager.VThink( iElapsedTime );
}
 
void CGame::VRender( SDL_Surface* pDestSurface )
{
	m_oTileManager.VRender( pDestSurface );
	m_OUnitManager.VRender( pDestSurface );
}
 
bool CGame::VLoad( TiXmlElement* pXMLData )
{
	if ( m_oTileManager.VLoad( pXMLData->FirstChildElement( "tiles" ) ) == false )
		return false;
 
	if ( m_OUnitManager.VLoad( pXMLData->FirstChildElement( "units" ) ) == false )
		return false;
	
	return true;
}
 
TiXmlElement CGame::VGetSaveData()
{
	TiXmlElement GameElm( "map" );
	GameElm.InsertEndChild( m_oTileManager.VGetSaveData() );
	GameElm.InsertEndChild( m_OUnitManager.VGetSaveData() );
 
	return GameElm;
}

Proceed to Part 8: Putting it all together


Table of Content - Part 1 - Part 2 - Part 3 - Part 4 - Part 5 - Part 6 - Part 7 - Part 8 - Part X