I'm a very beginning programmer and I'm struggling a bit with just how to structure my simple GapiDraw game and would appreciate any help.
I'm trying to design my game using classes to represent each phase of the game. For instance, the main menu would be one class, the introduction would be another, and the actual gameplay another. All of these classes would be derived from a base class which would have all of the functions of the CGapiApplication class. For instance, I'm calling my base class CMode. Cmode includes the following functions (although at the moment, I can't recall the parameters for each one):
virtual HRESULT CreateSurfaces(...) { return S_OK; };
virtual HRESULT ProcessNextFrame (...) { return S_OK };
virtual HRESULT StylusDown (...) { return S_OK; };
etc...
My idea is to override these functions in the derived classes. For instance, class CMainMenu : public CMode would override ProcessNextFrame () to draw the main menu and its various states. I have a global pointer, CMode* g_cpCurrentMode, that is set to the address of the currently active object. Then in CGapiApplication::ProcessNextFrame (), i have the following code:
g_cpCurrentMode->ProcessNextFrame (...);
So that the correct object processes the current frame. Similarly, I would call the CreateSurfaces, StylusDown and other functions in the derived classes from the corresponding CGapiApplication functions.
This works for me so far (I have only implemented a bare-bones main menu), but my question is: Is this a reasonable way to go about this? I'm very new at this, so I don't know if this is a good way to do this or not. Please let me know if any of this is unclear, and I'll try to clarify better.
Brad
I'm trying to design my game using classes to represent each phase of the game. For instance, the main menu would be one class, the introduction would be another, and the actual gameplay another. All of these classes would be derived from a base class which would have all of the functions of the CGapiApplication class. For instance, I'm calling my base class CMode. Cmode includes the following functions (although at the moment, I can't recall the parameters for each one):
virtual HRESULT CreateSurfaces(...) { return S_OK; };
virtual HRESULT ProcessNextFrame (...) { return S_OK };
virtual HRESULT StylusDown (...) { return S_OK; };
etc...
My idea is to override these functions in the derived classes. For instance, class CMainMenu : public CMode would override ProcessNextFrame () to draw the main menu and its various states. I have a global pointer, CMode* g_cpCurrentMode, that is set to the address of the currently active object. Then in CGapiApplication::ProcessNextFrame (), i have the following code:
g_cpCurrentMode->ProcessNextFrame (...);
So that the correct object processes the current frame. Similarly, I would call the CreateSurfaces, StylusDown and other functions in the derived classes from the corresponding CGapiApplication functions.
This works for me so far (I have only implemented a bare-bones main menu), but my question is: Is this a reasonable way to go about this? I'm very new at this, so I don't know if this is a good way to do this or not. Please let me know if any of this is unclear, and I'll try to clarify better.
Brad