State Pattern Demo
As an exercise I created a little program to illustrate how the State Pattern could be implemented with javaFX.
The program contains 2 nested State Machines. An AppMachine that is the high-level controller for the titleScreen and information screen. Other screens that might be used at this level are high score screens, preferences, and a copyright or contact screen.
The GameMachine has 3 states: playing the game, a victory screen and an defeat screen.
The beauty of the State Pattern is that you can add and move between new states easily.
The State Pattern used in this demonstration program is based on the State Pattern chapter in Head First Design Patterns.
The GameMachine has 3 states: playing the game, a victory screen and an defeat screen.
The beauty of the State Pattern is that you can add and move between new states easily.
The State Pattern used in this demonstration program is based on the State Pattern chapter in Head First Design Patterns.
Here is the jar file with the game. Just copy it to your computer and run it.
Note: You will need Java on your PC to run this. |
|
Here is the source code:
|
|