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 Knight extends Piece
{
   public Knight (int x, int y, int w, Color c, Player owner, int n, String set)
   {  
      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.fullPath = this.imagePath + set+ player.getPlayerColor() + "knight.png";
      this.img = Toolkit.getDefaultToolkit().getImage(fullPath);
   }
   
   public Knight (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.player = p.player;
      this.isNull = p.isNull;
      this.hasBeenMoved = p.hasBeenMoved;
      this.fullPath = this.imagePath + p.player.b.set + player.getPlayerColor() + "knight.png";
      this.img = Toolkit.getDefaultToolkit().getImage(fullPath);
   }

   /**
    *   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 goodMove = false;
      Point heading = new Point(0, 0);
      Point currentSpotCheck = new Point (0, 0);
      player.specialMove = "";

      heading.x = c - this.getCol();
      heading.y = r - this.getRow();
      
      if (heading.x == 0 && heading.y == 0)
      {
         return false;
      }
      
      if (Math.abs(heading.x) == 2 && Math.abs(heading.y) == 1 ||
          Math.abs(heading.x) == 1 && Math.abs(heading.y) == 2)
      {
         currentSpotCheck.x = this.pos.x + heading.x;
         currentSpotCheck.y = this.pos.y + heading.y;
         
         if (b.sq[c][r].hasPiece)
         {
            if (b.sq[c][r].contents.player == this.player)
            {
               return false;
            }
         }
         
         
         if (this.player.opponent.myKing.getCol() == c &&
             this.player.opponent.myKing.getRow() == r)
         {
            goodMove = true;
         }
         else
         {
            goodMove = tryMove(c, r, b, this.player);
         }
      }
      
      return goodMove;
   }
   
   /**
    *   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 "Knight";
   }
   
   public int pieceTypeID()
   {
      return 2;
   }
}
