Lookup "data driven programming", "virtual functions" and "function pointers"
http://en.wikipedia.org/wiki/Data-driven_programming
http://en.wikipedia.org/wiki/Virtual_function
short virtual function example:
bool quit = false;
class GameMode {
public:
virtual void Update() = 0;
};
class GameModePlatformer : public GameMode
{
public:
virtual void Update() {
// do stuff in platformer mode
}
};
class GameModeMenu : public GameMode
{
public:
virtual void Update() {
// do stuff in menu mode
}
};
GameModePlatformer game_mode_platformer;
GameModeMenu game_mode_menu;
void main()
{
GameMode *current_mode = &game_mode_menu;
while(!quit){
current_mode->Update();
render();
}
}
An actual game would have init and free functions and other details such as a convenient way to switch modes but that's the gist of it.