For practicing multi platform development I implemented a simple board game that is completely abstract. That means it contains all the logic and uses interfaces for the unknown or platform specific parts. For example:
- When crating an instance of the game, the implementation has to provide an
IPlayerinterface for the human player. In order to get the player's next move, the engine calls
GetNextMove()and the implementation has to provide the move. I implemented this for a text based console version which is using
ReadKey(). For iOS, swipe gestures are used.
- In order to display the current board,
IVisualizationServicehas to be implemented. For the console version, this simply uses ASCII art. The iOS version uses SpriteKit. Again, the engine calls an UpdateGameField() method.
The engine is running the
while(true) loop that is common to all games, performing calculations and calling out to the interface methods if required.
Now here's the question I cannot really find an answer to: currently, the abstract game is running in a separate thread in order to allow it to run without interrupting the UI thread. Somehow I think the approach is wrong. My gut feeling tells me that everything should run on the main thread and just schedule the required callbacks. The implementation would have to trigger the engine regularly. Can you please comment on the two approaches and maybe give examples for existing engines/samples/tutorials?