Got a problem I constantly run into when creating small games as programming practice. I am currently practicing keeping the game engine seperate from the game itself, passing the specific game into the engine so the latter can do its thing.
The problem I have is that when creating the Engine's functions, because I want it to process any game I throw at it, I have to use the parent class "Game" as the parameter being passed into the engine, instead of the specific game such as "Connect 4" or "Checkers". In so doing I lose all the functionality of the specific game when passing it into the engine.
Consider the following fragments that should demonstrate my problem:
I would like "CheckPlacementPossibility" to check with the specific game we've passed in that it's OK to place the counter where the user has requested (since where we can place a counter on the Connect 4 grid will be different to where we can place it on the Othello grid, for example). However, the complier refuses - instead it calls the CheckPlacementPossibility function straight from the parent class Game, where I have a statement that simply reads "you shouldn't be chaining this far up!". I would like the function to call CheckPlacementPossibility ()according to whichever type of Game I've passed in (such as Connect 4).
Connect4 C4Game; // The Game I will pass into the engine. Connect4 is a derivation of the Game class
Engine::PlaceCounter(Game& theGame) // A function in the engine to place counters in whatever game is passed in
unsigned short WhereToPlaceCounter;
cout << "Please choose where to place counter: ";
cin >> WhereToPlaceCounter;
As I've said I seem to run into this problem all the time and working around it tends to be ugly, legnthy, and often compromises what I originally set out to achieve. If anyone knows of a simple way to resolve this it would be greatly appreciated.