package TicTacToe;


/**
 * Matthew Amdur
 * MBA
 *
 * This class models the abstract piece class that all the other pieces will have
 * to subclass from. This class extends a GP.FilledRectangle, so all the subclasses
 * of it are are already instances of a filled square. The class provides 2
 * methods that its subcalsses must redefine: ShowShapw() and Counter(). ShowShape
 * is the method used to tell a square to show whatever kind of piece it is,
 * x or o. 
 *
 * A note about abstraction. So what does defining method here mean? By defining
 * methods in an abstract class, we make sure that any subclass of this class
 * redefines these methods. This way we can have a reference to some sort of piece,
 * what type we don't really know, nor do we need to. All we have to do is call
 * the method we want, and the computer will figure out what kind of piece we have
 * and then find that piece's method and execute it. Does this sound like a
 * familiar concept? Well..... its polymorphism.
 **/
 
  public abstract class Piece extends GP.Graphics.FilledRectangle implements BoardSize {

    /** This is the constructor for the Piece class. A constructor in
     * an abstract class? Yes, although the Piece class can never be
     * instantiated snce its abstract, other classes that subclass
     * from it can use this constructor by calling super(cont). That
     * way, if we want to change the size of all our pieces we can
     * just change it here as opposed to changing in every
     * class. Also, this constructor invokes the constructor of the
     * FilledRectangle, so the subclass inherit all the required
     * functionality.  
     */

    public Piece(GP.Container cont) {
      /**We call super(cont) so that we can inherit the GP functionality.**/

      super(cont);
      
      /**This sets the size and color of each square. By setting these here, we
	*can change the size and the colors of are board by altering two lines of
	*code as opposed to having to change it in each class. **/
      
      this.SetSize(new GP.Attributes.Size(SHAPE_WIDTH, SHAPE_WIDTH));
      this.SetColor(new GP.Attributes.Colors.Gray());
    }

    /**
     * This method is redefined by the subclasses to show their shape. XPiece's have
     * a reference to a GP.FramedTriangle, so when this method is called they
     * show their triangle, while OPiece's show a filled circle. BlankPiece 
     * redefines this method to do nothing, so that should this method ever get 
     * called on a blank piece nothing would happen.
     */

    public abstract void ShowShape();


    /** This method is redefined by the subclasss to return some
     * number. This method is used when checking to see if their is a
     * TicTacToe. The OPiece's return 1, the XPiece's return -1, and
     * the BlankPiece return 0. This way, we can just go down a row
     * adding up its values, and at the end see if the value we got is
     * equal to the size of the board, or - the size of the board. If
     * it is, that means that we have a TicTacToe and we need to take
     * the proper action. This way we can chek to see if someone won without ever
     * having to know what type of Piece is in each square.
     */

    public abstract int Counter();
  }
