import java.awt.*;
import javax.swing.*;
/**
  *  This class contains information and methods related
  *  to uncrowned pieces.
  *  @author Casey Daughtery, Joshua Canter, Yvon Feaster 
  *  @version 2.0
 */
 
public class Pawn extends Piece
{
   /**
    *   This constructor initializs all the necessary
    *   information for the Pawn class
    *   public
    *   @param x   x coordinate 
    *   @param y   y coordinate
    *   @param w   width
    *   @param c   color of the Pawn
    *   @param owner  an instance of Player
    *   @param n   the number of the current Pawn
   */
   public Pawn (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.checkerNumber = n;
      this.isNull = false;
   }
   
   /**
     *   This is a contructor that takes no params.
    */
   public Pawn ()
   {
      this.color = new Color(0, 0, 0);
      this.pos = new Point(0, 0);
      this.coord = new Point(0, 0);      
      this.player = null;
      this.isNull = true;
   }
   /**
     *   This is a contructor.
     *   @param  checker   An instance of Piece
    */   
   
   public Pawn (Piece checker)
   {
      this.color = checker.color;
      this.pos = new Point(checker.pos.x, checker.pos.y);
      this.width = checker.width;
      this.coord = new Point (checker.coord.x, checker.coord.y); 
      this.isNull = checker.isNull;
   }
   /**
     *   This method returns a boolean if the Piece is a king.
     *   @return  false if the Pawn is not a king
    */
   public boolean isKing ()
   {
      return false;
   }
 
   /**
    *   This method checks to see if a king move is valid.
    *   public
    *   @param isBlackSquare   true if the current square is occupiable
    *   @param isNotEmpty      true if the current square is occupied
    *   @param c               the x postion of the square that holds the pawn
    *   @param r               the y postion of the square that holds the pawn
    *   @param b               a reference to the board
    *	  @return                true if the move is valid
   */  
   public boolean isMoveValid (boolean isBlackSquare, boolean isNotEmpty, 
                               int c, int r, Board b)
   {
                
      if (isBlackSquare && !isNotEmpty)
      {         
         if(r == this.getRow() + 1 * this.player.direction)
         {
            if (c == this.getCol() - 1 || c == this.getCol() + 1)
            {
               return true;
            }
         }
          
         if(r == this.getRow() + 2 * this.player.direction)
         {
            if(c == this.getCol() - 2)
            {
               if (b.sq[this.getCol()-1]
                       [this.getRow()+1 * this.player.direction].
                       contents.player == this.player.opponent)
               {
                  return true;
               }
            }

            if(c == this.getCol() + 2)
            {
               if (b.sq[this.getCol()+1]
                       [this.getRow()+1 * this.player.direction].
                       contents.player == this.player.opponent)
               {
                  return true;
               }                
            }
         }
      }

      return false;
   }
   
   /**
    *   This method draws a king at the piece's location.
    *   public
    *   @param g      passed Graphic instance
    */
    
   public void drawChecker(Graphics g)
   {      
       GradientPaint checkerGrad = new GradientPaint(0 , 0, Color.magenta, 0,
                                                     0, Color.cyan);    

       Graphics2D g2 = (Graphics2D) g;
             
       g2.setColor(this.player.color);
       g2.fillOval(this.getXpos(),
                   this.getYpos(), 
                   this.getWidth(), 
                   this.getWidth());

       if (this.player.direction == 1)
       {
          checkerGrad = new GradientPaint(this.getXpos()-(width * 10 / 9),
                           this.getYpos()-(this.width * 10 / 9), Color.black,
                           this.getXpos()+(this.width * 6 / 9), 
                           this.getYpos()+(this.width * 6 / 9), Color.red);
       }
       if (this.player.direction == -1)
       {
          checkerGrad = new GradientPaint(this.getXpos(),
                           this.getYpos(), Color.black, 
                           this.getXpos()+(this.width * 20 / 9), 
                           this.getYpos()+(this.width * 20 / 9), Color.gray);
       }

       g2.setPaint(checkerGrad);
       g2.fillOval(this.getXpos()+(this.width * 1 / 9),
                   this.getYpos()+(this.width * 1 / 9), 
                   this.getWidth()-(this.width * 2 / 9),
                   this.getWidth()-(this.width * 2 / 9));
   }
}