import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import java.awt.Image;


public class ArcherInfantry extends Soldier {
     // OVERVIEW: A ArcherInfantry is a soldier that performace a walk,
    //    moving one square in a direction toward enemy each step.
    //      Attacks enemies untill dead or victorius
    // Low Life, Medium Damage, Slow, Special: arrows enemies up to 4 away


private boolean inTurn;

int maxhealth; 
  
public ArcherInfantry () {
	inTurn = false;
        setFight(false);
        setHealth(55);
        setSpeed(500);
      //  setAttacknum(1); //default is 1
        setDamage(8);
        maxhealth=getHealth();
        setExp(1);
       
    }

    public String getType()
    {   //Effect: returns soldier type
     return "Archer";   
    }
    
    public Color getColor()
    {   //Effect: returns soldier color or white if moving
	if (inTurn) {
	    return Color.white;
	} else {
	    return color;
	}
    } //@nowarn NonNullResult // ESC/Java doesn't know Color constants are not null

     public void drawWeapon( Graphics g,int x, int y,int w, int h, double rat)
    {    //Effect: displays soldier graphic
      

        int x2=x;int y2=y;

        int m=(int)(4*rat);
        x2=x+w/3;
        y2=y+h/15;

        int x3=x2;
        int y3=y2;

        if(fight)
        {
        x3+=w/3-(int)(2*rat);
        y3-=h/2-h/3;

        }
        else
        {
        x3+=w/3-(int)(2*rat);
        y3-=h/2-(int)(2*rat);

        }
       
        if((fight)&&(inTurn))
        {

        y3-=h/6;
        //y2-=w/5;
        x2-=w/5;

        }

        int x4=x2;
        int y4=y2;

        g.setColor(Color.darkGray);

        if(fight)
            g.setColor(Color.red);
          
       
        g.setColor(Color.yellow);
        g.drawArc(x2, y2, w/2, h/2+h/3,-45,100);
        
        x2+=(1*rat);
         y2+=(1*rat);

         g.setColor(Color.red);

     }

  
    public void drawMan(Graphics g,int x, int y,int w, int h)
    {    //Effect: displays soldier graphic
        double rat=w/50;


        drawBody(g,x,y,w,h,rat);
        if(getHealth() > maxhealth/3)
        drawWeapon(g,x,y,w,h,rat);

     }
    
    boolean Special()
    {
    
     Soldier ss1=Locate();
    
    if(ss1!=null) 
     if(Distance(ss1) <= 4)
     {
      
      int power = ss1.Hurt(5,1);
      System.out.println( toString()+ "\t Arrowed " + "\t" + ss1.toString() + "\t for damage:" + power );    
      return true;   
     }
     
     return false;
             
    }


    public void executeTurn() throws RuntimeException
       // Note: requires isInitialized is inherited from SimObject
       // EFFECTS: Picks a random direction and tries to move that way.
       //          If the move is successful, return true. If the move fails
       //          because the spot being attempted to move into is already
       //          occupied then return false.

    {
        if(getHealth()<1)
        {   
            Died();
            getGrid().killObjectAt(mrow,mcol);
            return;
        }
        
	inTurn = true;
              
        if(!  Attack()&&(!Special()))
            MoveTo();
     
      	inTurn = false;
    

    }
}