Programming Resources
For Fun and Learning
Charles Cusack
Computer Science
Hope College
main

Python
C++

JAVA


PHP
SQL
Alice

TargetGame


Description
Target Game description:
  • The TargetGame class hierarchy shows how the classes are related to each other, the aLibrary, swing, and other classes.
  • The TargetGame aggregation chart shows some of the aggregation and other relationships between classes related to the TargetGame.
  • Each of the classes used to implement TargetGame is described below, with the class diagram shown on the right.
  • ABullet is an abstract class that can be extended so that the subclass will draw bullets however the extender wishes.
  • LSBullet is an extension of ABullet that implements the drawing functions so that the bullet looks like a bullet from a Light Storm toy dart gun.
  • BulletTimer is an extension of EventTimer that is used to animate an ABullet firing. It was implemented to draw an LSBullet in particular.
  • AClip is an abstract class that can be extended so that the subclass will draw the clip however the extender wishes. an AClip holds bullets of type ABullet.
  • LSClip is an extension of AClip that implements the drawing functions so that the clip looks like a clip from a Light Storm toy dart gun. Notice that the arguments to the methods, and the array of bullets that is inherited are of type ABullet, even though the bullets put into the clip are probably of type LSBullet. Since LSBullets are ABullets, this is not a problem.
  • AClipGun is an abstract class that can be extended so that the subclass will draw the gun however the extender wishes. An AClipGun accepts an AClip and fires bullets of type ABullet.
  • LSGun is an extension of AClipGun that implements the drawing functions so that the gun looks like a Light Storm toy dart gun. Notice that the arguments to the methods (including the inherited methods) and the inherited instance variables are of types ABullet and AClip, even though the objects that will be passed are of types LSBullet and LSCip. Since an LSClip (LSBullet) is a AClip (ABullet), there is no problem with this. It is important to remember, however, if you need to pass an object of type LSClip to insertClip, for instance, your reference variable must be an AClip, not an LSClip, since the argument type is AClip and not LSClip. Again, since an LSClip is an AClip, a variable of type Aclip can refer to an object of type LSClip (But not the other way around).
  • ATarget is a class that implements a target that can be hit by ABullets. ATargets have various sizes, speeds, and values, and their movement is accomplished by using the TargetTimer.
  • TargetTimer is an extension of the EventTimer used to move ATargets on the screen.
  • ResetButton is an extension of AButton that resets the TargetGame when pushed.
  • GameTimer is an extension of EventTimer that is used by GameTimer so each level has a time limit.
  • TargetGame is a fun game which utilizes all of the classes described here. It places an LSClip and LSGun on the left side of the screen, and starts level 1. On level n, n ATargets are placed starting from the right side of the screen, and they start moving up and down, and slowly toward the left. The player has 100-5n seconds to shoot all of the targets, and wins if they complete level 20. Each bullet fired deducts points from the score, and each target hit adds points to the score. For more details, play the game and find out the rest.