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 Spell extends Soldier {
   // OVERVIEW: A Spell is a special of Wizards that performace a walk,
    //    moving one square in a direction toward enemy each step.
    //      Attacks enemies untill dead or victorius
    // Medium Life, Damage = life, Fast, Special: losses life every turn

    
    private boolean inTurn; // Currently in the middle of a turn (used for coloring)
    
   
    int maxhealth;
    
    public Spell () {
	inTurn = false;
        setFight(false);
       
       setHealth(15);
        
        
        setSpeed(250);
      //  setAttacknum(1); //default is 1
        setDamage(5);
       
        
        maxhealth=getHealth();
       // color=c1;
        
       
    }
    
    
   
   public String getType()
   {
    //Effect: returns soldier type
    return "Spell";   
   }
    
 
    
    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 drawSpell(Graphics g,int x, int y,int w, int h, double rat)
    {    //Effect: displays soldier graphic
        int x2=x;int y2=y;
        
        y2+=h/5;
        
        
        x2+=w/5;
        
        
        int size=(w/3+w/2);
        
        if(maxhealth < 20)
        {
           size-=w/4; 
        }
        
         
         g.setColor(getTeam());
        g.fillOval(x2,y2,size/2,size/2);
        
        
        
        g.setColor(Color.cyan);
        g.drawOval(x2,y2,size/2,size/2);
        int cc=0;
        for(int ww=size;ww >1;ww-=w/8)
        {
            
           g.setColor(Color.cyan);
           
           if(cc%2==1)
               g.setColor(getColor());
         
         cc++;
        g.drawOval(x2,y2,ww,ww);   
            
        }
      //  g.setColor(getColor());
      //  g.drawOval(x2,y2,size-=8,size-=8); 
        
        g.setColor(getTeam());
        g.fillOval(x2,y2,size/2,size/2);
        
    }

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


       
         drawSpell(g,x,y,w,h,rat);
       
    }
    


    public void executeTurn() throws RuntimeException
      // Note: requires isInitialized is inherited from SimObject
       // 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)
        {   
            System.out.println( toString()+ " has vanished" );
            getGrid().killObjectAt(mrow,mcol);
            pauseObject();
        
        return;
        }
        
       
	inTurn = true;
        
        
         setHealth(getHealth()-1);
	 setDamage(getHealth());
         
         
          if(!  Attack())
              MoveTo();
         
          delay (getSpeed());
         
	inTurn = false;
    
    
    }
}