6.8 Class GameElement

Class GameElement (Fig. 6.7)—the superclass of the Blocker, Target and Cannonball—contains the common data and functionality of an object that moves in the Cannon Game app.

Fig. 6.7 GameElement class represents a rectangle-bounded game element

Computer code has 46 lines.

6.8.1 Instance Variables and Constructor

The GameElement constructor receives a reference to the CannonView (Section 6.13), which implements the game’s logic and draws the game elements. The constructor receives an int representing the GameElement’s 32-bit color, and an int representing the ID of a sound that’s associated with this GameElement. The ...

Get Android How to Program, 3/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.