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

Python
C++

JAVA


PHP
SQL
Alice

TargetGame


BulletTimer.java

//-----------------------------------------------------------------------------
// Class: 	BulletTimer
// Author:	Written by Chuck Cusack
// Date: 	September 2001
// Description:
//-----------------------------------------------------------------------------
import aLibrary.EventTimer;
import java.awt.*;
import java.awt.event.*;
//-----------------------------------------------------------------------------

public class BulletTimer extends EventTimer {

//-----------------------------------------------------------------------------
// Instance Variables
//
    private ABullet theBullet;         // A reference to the bullet to be drawn
    private TargetGame myGame;           // The controlling director
//-----------------------------------------------------------------------------
// constructor
// Create the timer.
//
  public BulletTimer(ABullet A,TargetGame D) {
      super();
      theBullet=A;
      myGame=D;
  }
//-----------------------------------------------------------------------------
// postcondition: if the bullet is not going to extend past the end of the
// 	screen, move it forward by 10 units.
//      otherwise, remove the bullet from the screen.
// 	Also, checks to see if a target is hit, and if so,
//      removes the bullet from the screen.
//
  public void actionPerformed(ActionEvent e) {
      if(theBullet.getX()<myGame.getWidth()) {
          if(myGame.checkForHit(theBullet)) {
              theBullet.remove();
              myGame.repaint();
              this.stop();
          }
          else {
              theBullet.translate(10,1);
              theBullet.repaint();
              myGame.repaint();
          }
      }
      else {
          theBullet.remove();
          myGame.repaint();
          this.stop();
      }
  }

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