This sample demonstrates a very simple use of the framework.
In a toss game the player chooses between head and tail, then tosses a coin and either wins or looses depending on whether the coin side matches his choice or not.
Modeling and implementing this very simple turn-based game highlights the Model-View-Controller design of games using the framework and the straight-forward process from the game rules to the architecture and code.
This game does not need neither a context (therefore no update either) nor any user.
This game does not require any security, synchronization or visibility units.
Two handlers provide the input/output operations :
First for the Model (as in Model-View-Controller) which handles the core of the game, a strategy is required in order to properly handle the player order :
Then the View-Controller deals with the input/output :
In the sequence diagram the control loop is inside TossInput, which read() method returns when the player ends the game :
The creation diagram is straight-forward, classes are instanciated in the reverse order of the flow of control :
As described above an implementation is required only for the following objects :
The modularity of the design appears clearly and drives the implementation process safely.
The complete source code for this sample can be found in the jtge.sample.toss package.