package TicTacToe;


/**
 * Matthew Amdur
 * MBA
 *
 * First off: X's are represented by triangles. O's are represented by circles.
 * This is to emphasize how to manipulate GP shapes as opposed to loading in
 * images. Also, TicTacToe is so mainstream, I wanted something different. So
 * I made triangles.
 *
 * This is the Applet for the program. The Applet will instantiate other
 * classes that we need to play the game. In general, I like to have as 
 * little code in the applet as possible. This allows you to extend your
 * program later, since you can make multiple instances of it in the Applet,
 * as opposed to having to make multiple Applets.
 *
 * First, let me start by giving a general over view of my design. I have a 
 * TicTacToe class that takes care of making a new game. The TicTacToe class
 * instantiates the Board class. This class makes the actual board that you
 * play the game on. Each square on the board is actually an instance of a 
 * piece, the piece just doesn't have an x or an o. I made my board like this
 * so I could redefine my BlanlPiece's react method to tell the board to put
 * and x or and o in that space on the board. Each BlankSquare has a reference
 * to the board. They need references for the board to solve this problem.
 *
 *
 * Design Problem 1: If I have all these seperate boxes that don't know about
 * eachother, how do they know whether they need to make an x or an o?
 *
 * Solution: At first I thought I should have a holder pattern, each square
 * would have a reference to a holder, and when it needed to make an x or an
 * o it would get the piece from the holder. This, however, didn't seem to be
 * the best solution. Since every square already needed a reference to its
 * board, I decided to put the board in charge of making the new pieces. When
 * a blank piece is told to react, it tells the Board to insert a new piece
 * at its coordinates. The board keeps track of what the next piece is, and
 * makes sure that the game isn't over, since once the game ends you 
 * shouldn't be able to add more pieces to the board.
 *
 *
 * Design Problem 2: How do I make XPiece and OPiece draw an X or an O?
 *
 * Solution: Since each square needs to know its position in order to draw
 * itself correctly, why not just have each the X and O squares have an 
 * instance of a shape? We have all the pieces extend from a GP.Graphics.Filled
 * Square, and then the XPiece and OPiece each have their own instance of
 * another shape. We have a method that all Pieces redefine: ShowShape(). 
 * Those with a shape show their shape, the other do nothing. Hence, by using
 * polymorphism are squares display the right shape without us ever having to
 * know about which type of square is which.
 *
 *
 **/

public class Applet extends GP.Containers.Applet implements BoardSize {  
  
  /** We need this class in order to make a new game. This helps to take code
    * out of the applet, and make the progam more extensible. **/
  private TicTacToe _game;

  public Applet() {
    
    /**We want to get all the functionality of the GP applet, so we call 
      *super. **/
    
    super(); 
    
    /**Now we want to make the stuff actually appear, so we make an instance
      *of the TicTacToe class, which will make us a new game. **/

    _game = new TicTacToe(this);

    /**This adds a behavior to the applet, it makes the applet shrink wrap to
      *fit whats on the screen. This means that we don't have extra space or
      *not enough space on the screen. **/
    
    this.SetGeometryManager(new GP.Behaviors.GeometryManagers.Column());
  }

}
