import javax.swing.*;
import java.awt.*;
/**
 *   This class holds is used with Board to maintain 
 *   squares for a checker or chess board
 *   @author Casey Daughtery, Joshua Canter, Yvon Feaster
 *   @version 4.0
*/

public class Square
{
   protected Point pos, coord;
   protected int width;
   protected Color color;
   protected boolean isOccupiable;
   protected boolean hasPiece;
   protected Piece contents;

   /**
    *   This method constructs the square variables
    *   @param x  x coordinate
    *   @param y  y coordinate
    *   @param w  width
    *   
   */
   public Square(int x, int y, int w)
   {
      width = w;
      coord = new Point(x, y);
      pos = new Point (x * width, y * width);
      isOccupiable = (x % 2 != y % 2);
      hasPiece = false;
      color = new Color(128, 128, 128);
      color = Color.gray;
      contents = new Pawn();            
   } 
        
   /**
    *   This method gets protected information from the square class.
    *   (row - the row in the 8 X 8 board)
    *   
    *   @return      row as an integer
   */
   public int getRow()
   {
      return coord.y;
   }
 
   /**
    *   This method sets row.
    *   @param r    setting the row value
    *   
   */
    public void setRow (int r)
   {
       coord.y = r;
   }
 
   /**
    *   This method gets protected information from the square class.
    *   (col - the column in the 8 X 8 board)
    *   
    *   @return    x coordinate as an integer
   */  
   public int getCol()
   {
      return coord.x;
   }

   /**
    *   This method sets col.
    *   @param c  setting the row value
    *   
   */ 
   public void setCol (int c)
   {
      coord.x = c;
   }

   /**
    *   This method gets protected information from the square class.
    *   (xpos - the "x" postion of the square)
    *   public
    *   @return    x position in pixels 
   */   
   public int getXpos()
   {
      return pos.x;
   }
   /**
    *   This method sets xpos.
    *   public
    *   @param     x position in pixels
    *   
   */   
   public void setXpos (int x)
   {
      pos.x = x;
   }

   /**
    *   This method gets protected information from the square class.
    *   (ypos - the "y" position of the square)
    *   public
    *   @return    y position in pixels
   */   
   public int getYpos()
   {
      return pos.y;
   }

   /**
    *   This method sets ypos.
    *   public
    *   @param y    Setting the y position in pixels
   */
   public void setYpos (int y)
   {
      pos.y = y;
   }

   /**
    *   This method gets protected information from the square class.
    *   (width - the width of the square)
    *   public
    *   @return      returnin the width
   */   
   public int getWidth()
   {
      return width;
   }
 
    /**
    *   This method sets width.
    *   public
    *   @param w    setting the width
   */  
   public void setWidth (int w)
   {
      width = w;
   }
   
   /**
    *   This method gets protected information from the square class.
    *   public
    *   (color - the color of the square)
    *   @return    returning the color
   */   
   public Color getColor ()
   {
      return color;
   }

   /**
    *   This method sets color.
    *   public
    *   @param c    setting the color
   */   
   public void setColor (Color c)
   {
      color = c;
   }

   /**
    *   This method gets protected information from the square class.
    *   (isOccupieable - can the square recieve a checker)
    *   public
    *   @return    true if square is occupiable
   */   
   public boolean getIsOccupiable ()
   {
      return isOccupiable;
   }

    /**
    *   This method sets isOccupiable.
    *   public
    *   @param  is    setting if the square is occupiable
   */  
   public void setIsOccupiable (boolean is)
   {
      isOccupiable = is;
   }

   /**
    *   This method gets protected information from the square class.
    *   (hasPiece - does this square have a checker)
    *   public
    *   @return     true if the square has a Checker
   */
   public boolean getHasPiece ()
   {
      return hasPiece;
   }

   /**
    *   This method sets hasPiece.
    *   pubilc
    *   @param  has   setting the square to having a pawn or king
   */
   public void setHasPiece (boolean has)
   {
      hasPiece = has;
   }
   
  /**
   *   This method draws the squares on the board (JPanel)
   *   public
   *   @param  g    passed Graphics object to use in paint
  */
   public void drawSquare (Graphics g)
   {
      g.setColor(this.color);
      g.fillRect(this.pos.x, this.pos.y, this.width, this.width);
      if (this.hasPiece)
      {
         this.contents.drawPiece(g);
      }
   }
}//end class    