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

Python
C++

JAVA


PHP
SQL
Alice

TargetGame


Description

Run it
Download jar file (Right click)

ABullet.java
AClip.java
AClipGun.java
ATarget.java
AppletStarter.java
BulletTimer.java
GameTimer.java
LSBullet.java
LSClip.java
LSGun.java
ResetButton.java
TargetGame.java
TargetTimer.java

LSClip.java

//-----------------------------------------------------------------------------
// Class:   	LSClip
// Author:	Written by Chuck Cusack
// Date: 	September 2001
// Description: An extension of AClip that draws the clip to look similar to
//	a clip used in the Light Storm model toy guns.
//-----------------------------------------------------------------------------
import AClip;
import java.awt.*;
import aLibrary.*;
import java.awt.event.*;
//-----------------------------------------------------------------------------

public class LSClip extends AClip {

//-----------------------------------------------------------------------------
// The instance variables
//
                           // The graphical representation elements of the clip
    private ARectangle left,right,top,bottom,center;
//-----------------------------------------------------------------------------
// constructor
// Postcondition: draws the rectangles at location (x,y), and allows the
// 	clip to hold 14 bullets.
//
  public LSClip(int x,int y) {
      super(x,y,34,120,14); // 14 bullets...
  }

//-----------------------------------------------------------------------------
// draws the clip.
//
  protected void drawClip () {
      // Draw the various elements of the clip.
      center=new ARectangle(7,5,17,capacity*7+4);
      center.setToFill();
      center.setColor(Color.lightGray);
      center.place(this);

      left=new ARectangle(2,0,5,capacity*7+12);
      left.setToFill();
      left.setColor(Color.darkGray);
      left.place(this);

      right=new ARectangle(24,0,5,capacity*7+12);
      right.setToFill();
      right.setColor(Color.darkGray);
      right.place(this);

      // Creates the top of the gun, including a listener that
      // removes a bullet from the clip when the rectangle is clicked.
      top=new ARectangle(2,0,26,5) {
         public void mousePressed(MouseEvent e) {
           removeBullet();
           this.repaint();
           }
         };
      top.setToFill();
      top.setColor(Color.darkGray);
      top.place(this);

      // Creates the top of the gun, including a listener that
      // removes a bullet from the clip when the rectangle is clicked.
      bottom=new ARectangle(0,capacity*7+7,32,7) {
          public void mousePressed(MouseEvent e) {
              LSBullet b=new LSBullet(0,0);
              insertBullet(b);
              this.repaint();
              }
          };
      bottom.setToFill();
      bottom.setColor(Color.darkGray);
      bottom.place(this);
      this.repaint();
  }

//-----------------------------------------------------------------------------
// Draws the bullet A on the clip in the apporpriate place
//
  protected void drawBulletOnClip(ABullet A) {
            A.setLocation(9,6+(numberBullets-1)*7);
            A.place(this);
            this.repaint();
  }
//-----------------------------------------------------------------------------
// Remove the bullet that was last placed in the clip from the clip.
//
  protected void undrawBulletOnClip(ABullet A) {
          A.remove();
          this.repaint();
  }

//-----------------------------------------------------------------------------
}