An Undecorated Full-Screen (UFS) Worm
Figure 4-5 shows the UFS version of WormChase, a full-screen JFrame without a titlebar or borders.
The absence of a titlebar means I have to rethink how to pause and resume the application (previously achieved by minimizing/maximizing the window) and how to terminate the game. The solution is to draw Pause and Quit buttons on the canvas at the bottom-right corner. Aside from using the Quit button, ending the game is possible by typing the Esc key, Ctrl-C, the q key, or the End key. Data that were previously displayed in text fields are written to the canvas at the lower-left corner.
Figure 4-6 gives the class diagrams for the UFS version of WormChase, including the public methods.
A comparison with the AFS class diagrams in Figure 4-2 shows a considerable simplification of WormChase and fewer methods in WormPanel.

Figure 4-5. The UFS worm

Figure 4-6. Class diagrams for the UFS version of WormChase
The WormChase class no longer has to be a WindowListener and, therefore, doesn't contain window handler methods, such as windowClosing(). The pauseGame(), resumeGame(), and stopGame() methods in WormPanel are no longer required. The Worm class is unchanged, and the Obstacles class is altered only so it can call setBoxNumber() in WormPanel; this method was ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access