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 Maximus extends Soldier {
    // OVERVIEW: A Maximus is a soldier that performace a walk,
    //    moving one square in a direction toward enemy each step.
    //      Attacks enemies untill dead or victorius
    // Most Life, Most Damage, Fast, No Special: attacks up to 3

    
    private boolean inTurn; // Currently in the middle of a turn (used for coloring)
   
    int maxhealth;
    
    public Maximus () {
	inTurn = false;
        setFight(false);
        setHealth(150);
        setSpeed(350);
        setAttacknum(3); //default is 1
        setDamage(25);
        setExp(3);
        
        maxhealth=getHealth();
       // color=c1;
        
       
    }
    
    public String getType()
    {   //Effect: returns soldier type
     return "Maximus";   
    }
   
   
    
 
    
    
    
    
    
    
    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 drawShield(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+m;
        y2=y+h/3-m;
        
        
         
        if(!inTurn)
        {
        m=(int)(4*rat);    
        //x2+=w/4;
        g.setColor(Color.black);
        g.fillRect(x2,y2+m,w/3-m,h/3);
        g.setColor(Color.yellow);
        
       // m-(int)(1*rat);
        g.drawRect(x2,y2+m,w/3-m,h/3);
        x2+=(int)(4*rat);
       // x2+=(int)(2*rat);
        x2+=(int)(3*rat);y2+=(int)(2*rat);
        g.drawRect(x2,y2+m,w/3-5-2*m,h/3-4);
         
        }
        else
        {
         m=(int)(4*rat);    
        x2+=w/4;
        x2-=2*m;
        g.setColor(Color.black);
        g.fillRect(x2,y2+m,w/3-m,h/3);
        g.setColor(Color.yellow);
        
       // m-(int)(1*rat);
        g.drawRect(x2,y2+m,w/3-m,h/3);
        x2+=(int)(4*rat);
       // x2+=(int)(2*rat);
        x2+=(int)(3*rat);y2+=(int)(2*rat);
        if(fight)
            g.setColor(Color.yellow.brighter());
        
        g.drawRect(x2,y2+m,w/3-5-2*m,h/3-4);
                    
        }
            
    }
    
    
    
     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+w/3;
        y2=y+h/2;
        
        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.drawLine(x2,y2,x3,y3);
        x2+=(1*rat);
         y2+=(1*rat);
         
         g.setColor(Color.darkGray);
         
        g.drawLine(x2,y2,x3,y3);
        x2+=(1*rat);
         y2+=(1*rat);
        g.drawLine(x2,y2,x3,y3);
        x2+=(1*rat);
         y2+=(1*rat);
        g.drawLine(x2,y2,x3,y3);
        x2+=(1*rat);
        
        if(fight)
            g.setColor(Color.red);
        
        g.drawLine(x2,y2,x3,y3);
        
        
        
        
        g.setColor(Color.black);
        
        x4-=2;
        
        g.fillRect(x4,y4,5,5);
        
        g.drawLine(x4,y4,x2,y2);
         x4+=(1*rat);
         y4+=(1*rat);
         g.drawLine(x4,y4,x2,y2);
          x4+=(1*rat);
         y4+=(1*rat);
         g.drawLine(x4,y4,x2,y2);
          x4+=(1*rat);
         y4+=(1*rat);
         g.drawLine(x4,y4,x2,y2);
     }
    
    
        
    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);
        drawWeapon(g,x,y,w,h,rat);
                
        
        drawWeapon(g,x-w/4,y+w/8,w,h,rat);
        drawShield(g,x-w/6,y+w/15,w,h,rat);
        
        if(getHealth() > maxhealth/7)
        drawShield(g,x,y,w,h,rat);
        
    }
    


    public void executeTurn() throws RuntimeException
       // Note: requires isInitialized is inherited from Soldier
       // EFFECTS: if enemy one away attacks first, closest enemy with for damage  
       // if not attacking Picks a direction closer to enemy 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.
       //          then delays for given speed
    {
        
        
        
        if(getHealth()<0)
        {   
            Died();
            getGrid().killObjectAt(mrow,mcol);
                
        return;
        }
        
       int newrow =0;
       int newcol=0;
        
       inTurn = true;
     
        
       if(!Attack())
           MoveTo();
       
        delay (getSpeed());
       
	

	inTurn = false;
    
    
    }
}