Im creating a simple game. very simple. just as a test for the console library im working on, problem is, ive got zero experience with game writing in C++, so advice on the following would be appreciated.
ive currently got the CApp class sorted, which is the main application. loop is setup and running too.
Example main.cpp
Code:
#include "CApp.h"
int main(int argc, char *argv[])
{
CApp *thapp = new CApp();
delete theapp
}
example CApp.h
Code:
#include <ConLib.h>
class CApp
{
public:
constructor();
destructor();
ConLib c_cmd; // My own console library (just a class with functions e.g c_cmd.WriteToScreen(text) )
Init();
Execute(); <-- this is the loop, every cycle do whats in here
Cleanup();
Exit();
}
Now im wanting to add a CGame class which would have a functions such as InitGame, ShowMenu, GenerateMap, etc, think very simple roguelike. Ive properly setup this wrong, but how would i allow a function such as CGame::ShowMenu to output to the screen via c_cmd in CApp? Or should i just declare another console library object for it to use in the CGame class.
Not sure if ive explained it right or not, kinda confused myself.
For example my original thought was to do this:
CApp.h -
Code:
#include "CGame.h"
class CApp
{
...
CGame thegame;
}
CApp::OnExecute -
Code:
void CApp::OnExecute
{
thegame.input();
thegame.think();
thegame.output();
}
CGame_Output.cpp
Code:
#include "CApp.h"
void CGame::output()
{
// need to access ConLib c_cmd from CApp here.
CApp::c_cmd.WriteToScreen("output here");
}
Is that last section for CGame_Output.cpp the right way to go? have i missed something?