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

Python
C++

JAVA


PHP
SQL
Alice

TargetGame


LSGun.java

//-----------------------------------------------------------------------------
// Class: 	LSGun
// Author:	Written by Chuck Cusack
// Date: 	September 2001
// Description: An extension of AClipGun that is drawn to look like a
//	Light Storm toy gun.  O.K. It looks more like a 9mm or something.
//-----------------------------------------------------------------------------
import java.awt.*;
import aLibrary.*;
import java.awt.event.*;
//-----------------------------------------------------------------------------

public class LSGun extends AClipGun {

//-----------------------------------------------------------------------------
// instance variables
//
    private ARoundRectangle body,handle,barrel; // The body, handle and barrel
    private AOval triggerA, triggerB;           // parts of trigger
    private AOval triggerC, triggerD;           // more parts of trigger
    private ARoundRectangle clipThing;          // clip release.
//-----------------------------------------------------------------------------
// The constructor
// Postcondition: myClip==null, and the gun is drawn as specified in drawGun.
//
  public LSGun(int x,int y,TargetGame d) {
      super(x,y,200,120,d);
  }
//-----------------------------------------------------------------------------
// Draw the gun so it looks like a 9mm or similar
//
  protected void drawGun() {
    triggerA=new AOval(25,25,40,40);
    triggerA.setToFill();
    triggerA.place(this);
    triggerB=new AOval(30,30,30,30);
    triggerB.setToFill();
    triggerB.setColor(Color.white);
    triggerB.place(this);

    // the part of the trigger that is displayed will fire if clicked.
    triggerC=new AOval(40,35,20,20) {
        public void mousePressed(MouseEvent e) {
           fire();
    	}};
    triggerC.setToFill();
    triggerC.place(this);

    triggerD=new AOval(45,40,15,18);
    triggerD.setToFill();
    triggerD.setColor(Color.white);
    triggerD.place(this);

    body=new ARoundRectangle(0,0,120,40);
    body.setToFill();
    body.place(this);

    handle=new ARoundRectangle(0,0,35,110);
    handle.setToFill();
    handle.place(this);

    //
    clipThing=new ARoundRectangle(10,101,15,10);
        /*{
        public void mousePressed(MouseEvent e) {
          AClip A=removeClip();
          A.setLocation(5,200);
          A.place(parent);
        }};*/
    clipThing.setToFill();
    clipThing.setColor(Color.white);
    clipThing.place(this);

    barrel=new ARoundRectangle(0,0,150,20);
    barrel.setToFill();
    barrel.place(this);
    this.repaint();
  }

//-----------------------------------------------------------------------------
// Draw the clip so it looks like it is in the gun.
//
  protected void drawClipInGun(AClip theClip) {
      theClip.remove();
      theClip.setLocation(1,1);
      theClip.place(this);
      handle.place(this);
      clipThing.setColor(Color.gray);
      clipThing.place(this);
      this.repaint();
  }
//-----------------------------------------------------------------------------
// Draw the gun so it does not have a clip drawn in it.
//
  protected void drawClipNotInGun() {
      if(myClip!=null) {
        myClip.remove();
        clipThing.setColor(Color.white);
        clipThing.place(this);
        this.repaint();
      }
  }

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