This is a re-writing of a text-based game I did last year. Back then I also requested a code review and was lucky Oler1s and baavgai ran into my thread, as they were of great help. Not much has changed in terms of actual content (I only added support for images and sound), but the code has changed almost entirely. The reason I'm doing the same thing again is because my focus is on learning good programming practices and correctly applying different programming patterns, and not on doing an actual game. At least for now.
Download source (105kB)
Includes VC10 and PN project files.
PROGRAM STRUCTURE
The main loop is located in main(), main.cpp:
GameManager game;
while (game.isRunning()) {
game.update();
game.render();
}
GameManager holds an std::vector of GameState objects; the last GameState in the vector is the currently active state. When GameManager::update()/render() get called from the main loop, GameManager calls the update()/render() functions of the currently active GameState.
It also holds the only instances of the GraphicsRenderer, SoundRenderer, and UserController classes in the application. It passes these instances around to the GameState objects, when it is required to.
The GameManager class also has change/push/popState() functions. When it update()-s the active state, the GameManager gives the state a pointer of itself so that the state would be able to change the currently active GameState.
void GameManager::update()
{
if (!stateStack_.empty())
stateStack_.back()->update(this, userController_);
}
void GameManager::render()
{
if (!stateStack_.empty())
stateStack_.back()->render(graphicsRenderer_);
}
This post has been edited by diego_pmc: 19 June 2010 - 11:41 AM

New Topic/Question
Reply



MultiQuote





|