import java.awt.*;
import javax.swing.*;
/**
  *  This class contains information and methods related
  *  to uncrowned pieces.
  *  @author Casey Daughtery, Joshua Canter, Yvon Feaster 
  *  @version 4.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.pieceNumber = n;
      this.isNull = false;
      this.hasBeenMoved = 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 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 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 (int c, int r, Board b)
   {
      if(!hasBeenMoved && r == this.getRow() + 2 * this.player.direction &&
         c == this.getCol() &&
         b.sq[c][r].hasPiece == false)
      {
         return true;
      }
      
      if(r == this.getRow() + this.player.direction && 
         c == this.getCol() &&
         b.sq[c][r].hasPiece == false)
      {
         return true;
      }
      
      if(r == this.getRow() + this.player.direction &&
         (c == this.getCol() + 1 || c == this.getCol() - 1) &&
         b.sq[c][r].hasPiece == true)
      {
         if (b.sq[c][r].contents.player == this.player.opponent)
         {
            return true;
         }
      }
      
      return false;
   }
   
   public String pieceType()
   {
      return "Pawn";
   }
   
   /**
    *   This method draws a king at the piece's location.
    *   public
    *   @param g      passed Graphic instance
    */
   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("Pawn", this.getXpos() + this.width / 2, 
                             this.getYpos() + this.width / 2);
   }
}