Code the Game logic
To control the game logic, we will encapsulate it in a game object right in the thick of the game and provide the necessary communication connections out to other game objects and inward from other game objects. This communication will be in the form of pointers to key values. For example, all objects will have a pointer to the logic-related game object to know such things as when the game is paused, among other things.
The idea of putting the game logic in a separate class is interesting. Consider a scenario if your game should have three different game modes. Imagine the confusing mess of if
, else
, and else if
statements that would be required if we incorporated all that logic into the main function. This way, the factory can simply pick a game object based on the game mode the player chooses. While this game will only have a single game mode, once you see the code, creating a different set of logic in a different class will be trivial.
Note that there...