import java.awt.*;
import javax.swing.*;

/**
 *   This class contains information and methods associated with the piece 
 *   for a checker board
 *   public
 *   @author Casey Daughtery, Joshua Canter, Yvon Feaster
 *	 @version 4.0
*/
public class Queen extends Piece
{
   public Queen (int x, int y, int w, Color c, Player owner, int n)
   {  
      this.color = new Color(255, 255, 255);
      this.color = c;
      this.pos = new Point(x, y);
      this.width = w;
      this.coord = new Point (x / width, y / width);
      this.player = owner;
      this.pieceNumber = n;
      this.isNull = false;
      this.hasBeenMoved = false;
   }
   
   public Queen (Piece p)
   {
      this.color = p.color;
      this.pos = new Point(p.pos.x, p.pos.y);
      this.width = p.width;
      this.coord = new Point (p.coord.x, p.coord.y); 
      this.isNull = p.isNull;
      this.hasBeenMoved = p.hasBeenMoved;
   }
   /**
    *   This method check to see if a checker move is valid.
    *   public
    *   @param isBlackSquare   true if it is occupiable square
    *   @param isNotEmpty      true if the square has a piece
    *   @param c               destination of x coordinate
    *   @param r							 destination of y coordinate
    *   @param b               a reference to Board
    *	  @return                true if the move is valid
   */  
   public boolean isMoveValid (int c, int r, Board b)
   {
      boolean isDiagonalMove;
      
      Point heading = new Point(0, 0);
      Point currentSpotCheck = new Point (0, 0);

      heading.x = c - this.getCol();
      heading.y = r - this.getRow();

      isDiagonalMove = (Math.abs(heading.x) == Math.abs(heading.y) 
                        && heading.x != 0);

      if (heading.x != 0)
      {
         heading.x = heading.x / Math.abs(heading.x);
      }
      
      if (heading.y != 0)
      {
         heading.y = heading.y / Math.abs(heading.y);
      }
      
      if (heading.x == 0 && heading.y == 0)
      {
         return false;
      }
      
      if (Math.abs(heading.x) == 1 && Math.abs(heading.y) == 0 ||
          Math.abs(heading.x) == 0 && Math.abs(heading.y) == 1 ||
          isDiagonalMove)
      {
         currentSpotCheck.x = this.getCol() + heading.x;
         currentSpotCheck.y = this.getRow() + heading.y;
                  
         while (currentSpotCheck.x != c ||
                currentSpotCheck.y != r)
         {
            if(b.sq[currentSpotCheck.x][currentSpotCheck.y].hasPiece)
            {
               return false;
            }
            currentSpotCheck.x += heading.x;
            currentSpotCheck.y += heading.y;
         }
         
         if (b.sq[c][r].hasPiece)
         {
            if (b.sq[c][r].contents.player == this.player)
            {
               return false;
            }
         }
         
         return true;
      }
      
      return false;
   }
   
   /**
    *   This method is a forward declaration for the draw methods in King 
    *   and Pawn.
    *   public
    *   @param g      the passed Graphics object
    */   
//   public abstract void drawPiece(Graphics g);
   
   /**
     *  This method is a forward declaration for a functor that 
     *  returns whether or not the piece is a King.
     *  public
     *  @return     True if the piece is a member of the King
    */
   public String pieceType()
   {
      return "Queen";
   }
   
   public void drawPiece(Graphics g)
   {      
       GradientPaint checkerGrad = new GradientPaint(0 , 0, Color.magenta, 0,
                                                     0, Color.cyan);    

       Graphics2D g2 = (Graphics2D) g;
       
       //AntiAliasing
       RenderingHints renderHints =
       new RenderingHints(RenderingHints.KEY_ANTIALIASING,
       RenderingHints.VALUE_ANTIALIAS_ON);
       renderHints.put(RenderingHints.KEY_RENDERING,
       RenderingHints.VALUE_RENDER_QUALITY);
       g2.setRenderingHints(renderHints);
             
       g2.setColor(this.player.color);
       g2.fillOval(this.getXpos(),
                   this.getYpos(), 
                   this.getWidth(), 
                   this.getWidth());

       if (this.player.playerNumber == 1)
       {
          checkerGrad = new GradientPaint(this.getXpos()-(width * 100 / 90),
                     this.getYpos()-(this.width * 100 / 90), Color.black,
                     this.getXpos()+(this.width * 60 / 90), 
                     this.getYpos()+(this.width * 60 / 90), this.player.color);
       }
       if (this.player.playerNumber == 0)
       {
          checkerGrad = new GradientPaint(this.getXpos(),
                     this.getYpos(), this.player.color, 
                     this.getXpos()+(this.width * 200 / 90), 
                     this.getYpos()+(this.width * 200 / 90), Color.gray);
       }

       g2.setPaint(checkerGrad);
       g2.fillOval(this.getXpos()+(this.width * 10 / 90),
                   this.getYpos()+(this.width * 10 / 90), 
                   this.getWidth()-(this.width * 20 / 90),
                   this.getWidth()-(this.width * 20 / 90));
                   
       g2.setColor(Color.white);
       g2.drawString("Queen", this.getXpos() + this.width / 2, 
                             this.getYpos() + this.width / 2);
   }
}