//
//  Program III:   The Mobile, Intelligent Turret!
//
//    Write a class that implements the following interface.
//


import java.awt.*;


public class nickturret implements Turret
	   {
		   int Tx;
		   int Ty;
		   int integ;
		//  Sets the turret location to inX, inY and the initial
		//     "integrity" of the turret to "initial_integrity"
		//     (inX, inY) is center of turret, more or less
        public void initialize(int inX, int inY, int initial_integrity)
			{
			Tx = inX;
			Ty = inY;
			integ = initial_integrity;
			}

        //  Paints the turret at its current location in the
        //     graphics object g.  If turret integrity is positive
        //     then paint turret onw way, otherwise paints a "destroyed"
        //     turret.  Turret fits into a 24 by 24 box.
	    public void paint(Graphics g)
	    	{
				g.drawRect(Tx,Ty,24,24);
	    		if (integ > 10)
	    		g.setColor(Color.blue);
	    		else if (integ > 0)
	    		g.setColor(Color.gray);
	    		else g.setColor(Color.green);
	    		g.fillRect(Tx,Ty,24,24);
	    		g.setColor(Color.red);

			}

	    //  Returns true if the coordinate (incomingX, incomingY) is
	    //    more or less inside of the turret's boundaries
	    public boolean inside(int incomingX, int incomingY)
	    	{
				if ((Tx < incomingX) && (incomingX < Tx+24) && (Ty < incomingY) && (incomingY < Ty+24))
				return true;
				else return false;

			}

	    //  Move the turret up the screen by "pixels" number of pixels.
	    public void moveUP(int pixels)
			{
				Ty-=pixels;
			}
	    //  Move the turret down the screen by "pixels" number of pixels.
	    public void moveDOWN(int pixels)
			{
				Ty+=pixels;
			}

	    //  Move the turret across screen by "pixels" number of pixels.
        public void moveRIGHT(int pixels)
			{
				Tx+=pixels;
			}
        //  Move the turret across screen by "pixels" number of pixels.
        public void moveLEFT(int pixels)
        	{
				Tx-=pixels;
			}

        //  Reduce the turret's integrity by "how_much", without
        //    going below zero.
        public void take_Damage(int how_much)
        	{
				if (integ > 0)
				integ = integ-how_much;

			}

        //  Return the current value of the integrity of the turret
        //    (note that this must be >= 0 and <= initial_integrity
        public int report_integrity()
        	{
				return integ;
			}
        //  Given the coordinate (fromX, fromY) of the origin of
        //     an incoming missle, fire back a particle beam in the
        //     the direction given by the returned integer.  This
        //     int is the angle of the beam outgoing from the turret,
        //     where due North (UP) is 0 degrees and due East (RIGHT)
        //     is positive 90 degrees, etc.  (So 360 and 0 both fire
        //     due North).
        public int return_fire(int fromX, int fromY)
        	{
				return 45;
			}

       }

