package TicTacToe;


/**
 * Matthew Amdur
 * MBA
 *
 * This class helps to extract code from the Applet. When it is instantiated
 * it makes a new Board, which in turn gives us the game that we want to play.
 * I decided to have this class so that if I wanted to, I could have many
 * TicTacToe games going on at once. This way, if I want 7 games, I can just
 * make 7 instances of this class. It is good practice to try to keep as little
 * code in the applet as possible. Why? Extensibility. If I had all this in 
 * the applet, how could I make two seperate games? I'd need to make two 
 * applets. But do I know how to do that? Well... lets assume no, so this
 * provides an elegant solution.
 **/

public class TicTacToe implements BoardSize {

  /** This class has an instance of the Board class. The Board class, when
    * instantiated makes a new Board with the number of squares alloted
    * in the BoardSize interface. Once this is done, the game is ready to
    * be played, since the squares take care of figuring out whose turn it
    * is. We also have an instance of a frame. Since each individual square on
    * on the Board is positioned, and we call the row GeometryManager on the 
    * applet, we need all the squares in some other container so they are not
    * put in a row. Hence, we make a frame and shrink the applet around the
    * frame. We also have a refernece here to a GP.Graphics.Text. We instaniate
    * the text here so that we can place in the container, not the frame. That way
    * we can let the GeomeryManager called on the Applet position the text
    * below the board. **/

  private Board _board;
  private GP.Containers.Frame _frame;
  private GP.Graphics.Text _text;

  /**
   * This is the constructor for the TicTacToe class. When we make a new 
   * instance of TicTacToe, we make a new frame and a new Board. See the 
   * comments below to find out why and how.
   */

  public TicTacToe(GP.Container cont) {
    /**This makes a new frame to put the board in, and sets it size based on
      *how big the game is. We can change the 3x3 dimentions to whatever we
      *want, since we used an interface to decide how big our board is.
      *FRAME_SIZE is set in the BoardSize interface, and is calculated by
      *the number of pieces and their sizes. We also set the color of the frame
      *to be black, so that it looks like we have lines in between the squares 
      *that we use to draw our board. **/

    _frame = new GP.Containers.Frame(cont);
    _frame.SetSize(new GP.Attributes.Size(FRAME_SIZE, FRAME_SIZE));
    _frame.SetColor(new GP.Attributes.Colors.Black());
    
    /**Now we make the Board, and we pass this new frame so that the Board
      *uses the frame as its container. This means that the Board will put
      *all the squares (that make up the board) in the frame. **/

    /**We need to instantiate the text here since we want it to appear in the
      *Applet container, not in the frame. This way, we pass each new board its
      *text when it is instantiated. **/

    _text = new GP.Graphics.Text(cont, "");


    _board = new Board(_frame, _text);
  }
}
