6.10 Target
Subclass of GameElement
Class Target
(Fig. 6.9)—a subclass of GameElement
—represents a target that the player can destroy. Class Target
’s hitPenalty
is added to the remaining game time if the Cannonball
collides with a Target
. The getHitReward
method (lines 17–19) returns the hitReward
—this method is called from CannonView
’s testForCollisions
method when adding the hitReward
to the remaining time (Section 6.13.11). The Target
constructor (lines 9–14) passes its arguments and the ID for the target-hit sound (CannonView.TARGET_SOUND_ID
) to the super constructor (line 11), then initializes hitReward
.
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.