SLIDE 1
Page 1
Design Pattern Exercises with the Asteroids Game Example
[from a book chapter “Teaching Design Patterns” by Bernd Brügge and Timo Wolf] Asteroids Game Description The Asteroids player controls a space shuttle on a game board, representing the outer space. Two different types of asteroids are also present on the game board: (a) small and fast asteroids, which change their direction only when they hit the edge of the game board, and (b) big and slow asteroids, which may change their direction any time. All asteroids can change their speed, ranging from a minimum to a maximum speed. The player can fire rockets and change the direction and speed of the space shuttle by using the keyboard. Striking a big asteroid with a rocket replaces the big asteroid with three small asteroids. Striking a small asteroid removes the asteroid from the game board. The player wins if he destroys all asteroids. He loses if his space shuttle collides with any asteroid. Figure 1 shows a screenshot of the initial version of Asteroids.
Figure 1. Screenshot of the initial Asteroids game.
- Fig. 2 shows the initial class diagram obtained from the game description. We focus on the main
classes and concepts and omit unnecessary details. In the following we describe the classes of
- Fig. 2: