package TicTacToe;

/**
 * Matthew Amdur
 * MBA
 *
 * This class modelts the blank square in the board, I.E. a place where there
 * is not an X nor an O. This clas subclasses from Piece, so it also indirectly
 * subclasses from GP.Graphics.FilledRectangle. Since it inherits all the
 * functionality of a GP.Graphic, it has a method React() that gets called 
 * whenever the mouse clicks on this shape. So, the BlankPiece is just a square
 * with no x or o, but it reacts when clicked on. When the square is clicked on,
 * it tells the Board to insert a piece at its coordinates (it knows where it is
 * in the array. The Board deals with figuring out whose turn it is and such.
 *
 * Design note: The BlankPiece takes the place of null in the array. This is very
 * useful since it allows us to call methods on everything in the array without
 * ever needing to check to see if the element is null. It also emphasizes 
 * polymorphism.
 */

public class BlankPiece extends Piece implements BoardSize {

  /**A BlankPiece needs to know its position in the array so it can tell the
    *the Board where to insert the new picee, so it holds this info in two integer
    *variables. It also needs a reference to the Board so it can tell the Board
    *to insert the new piece. **/

  private int _xIndex, _yIndex;
  private Board _board;

  /**
   * This is the constructor for the BlankPiece. When we make a BlankPiece we need
   * to set its color to be red, and then position it on the right place on the
   * screen. We also need to set the BlankPiece's reference to the Board, and we
   * need to tell it the values of its array indexes so it knows where it is. The
   * super call gets it its size, and all its other required functionality.
   */

  public BlankPiece(GP.Container cont, Board board, int xIndex, int yIndex) {
    /**We use the super classes constructor first to set the size.**/
    super(cont); 

    /**We need to set the position of the squares to make it look like a TicTacToe
      *Board. Rather than copying all the math for every place we need to position,
      *or instantiating a poistioner class, we have a class Positioner that has a
      *static method. To learn more about Static methods, look at the Positioner
      *class. Quickly, it is a method that can be called without having to 
      *instaniate the class. This method takes the array index and computes the
      *on screen position. **/

    this.SetPosition(new GP.Attributes.Position(Positioner.GetPosition(xIndex), Positioner.GetPosition(yIndex)));
    
    /**Now we initialize all the variables that got passed in as parameters when
      *the class was instantiated. We need these values in order to be able to tell
      *the Board where to insert the new Piece. **/
    
    _board = board;
    _xIndex = xIndex;
    _yIndex = yIndex;
  }

  /**
   * This method must be redefined here since it is defined in the abstract 
   * super class. Since a BlankPiece doesn't have a shape to show, the method is
   * redefined to do nothing. It might seem pointless, but if you don't redefine
   * the method, you can't instantiate the class, you get a compiler error.
   */

  public void ShowShape() {
  }

  /**
   * This method is used to insert the new piece into the array, and show it on the
   * board. It is defined in the GP.Graphics.FilledSquare, and is automatically
   * called whenever this Shape is clicked on. The method has been redefined to
   * tell the board to insert a new XPiece or OPiece at this location. The 
   * BlankPiece doesn't know what Piece needs to be put in its place, nor if
   * the game is over and nothing should be inserted, this is all left to the
   * Board. Hence, it is a very simple method: it delegates most of its authority
   * to the Board, since the Board has the information needed to insert the Piece.
   */

  public void React() {
    _board.InsertPiece(_xIndex, _yIndex);
  }

  /**
   * This method is used to check to see if there is a TicTacToe, since we add
   * up the values of each row and column. Since a BlankPiece doesn't help
   * you get a TicTacToe, it returns 0. This is still very useful though, since it
   * means that when we are trying to figure out if there is a TicTacToe we never
   * need to check to see if a ocation in the array is null before we call a method
   * on it.
   */

  public int Counter() {
    return 0;
  }
}
