
Learning Java by Building Android Games
By :

Now that we are well versed on how the Observer pattern works, and we have had a good look at the interfaces we will need to write, and how they will be used, we can put all the theory into practice in the Scrolling Shooter project.
As the specific use for our broadcaster and observers is to handle the player's input, we will code a class to handle the screen touches for the HUD. As a reminder, the GameEngine
class will be a Broadcaster, and the two separate classes that handle user input will be Observers. As the HUD and the player's spaceship are very different things, it makes sense for each of them to handle their own input.
We will code the UIController
class, which will be our first observer (for the HUD play/pause button) in this section and later in the project, we will code our second observer to handle the spaceship controls.
Tip
As we have learned, there is nothing stopping us adding more observers or...