/******************************80 Columns Wide******************************

Program:                   Tic Tac Toe game player

Author:                    Michael Ervin
Collaborators:             Um, my super intelligent cat.

Due Date:                  When it's done.
Completion Date:           Now

Course:                    CS 302, Fall '99, Section 306
TA:                        Me (hey, these are also my initials)
Assignment:                -1

Compiler:                  JDK 1.2
Platform:                  Solaris (will run on any platform)

Description:    
   This program uses the TicTacToe class to demonstrate a TicTacToe
   game. Some erroneous input to a function is trapped an and error
   message is displayed. After this, the game is reset and then 
   a new game is played to completion. The game is diplayed, reset and
   then displayed again.

Known Bugs:                There may be some, I don't know of any.


*******************************80 Columns Wide******************************/

class Game 
{

  public static void main(String args[])
  {
    TicTacToe t = new TicTacToe();

    // start a game

    /* note: ! mean "not", we know t.setVal(1,2)
       returns true or false. We in essence, flip it's value. So
       we are asking if the value is NOT set correctly.
    */

    // check for an error, though this one isn't.
    if(!t.setVal(1, 2))
      System.out.println("Error, square value not set!");

    // output value
      System.out.println("Square 1 has a value: " + t.getVal(1));
 
    // Oops! this one really is an error and will print that fact.
    // It's like try to put a @ on the board or something.
    if(!t.setVal(2,4))
      System.out.println("Error, square value not set!");
   
    // reset game values
    t.resetGame();
   
    // start another game an place Xs and Os on the board
    t.setVal(1, 1);
    t.setVal(5, 2);
    t.setVal(7, 1);
    t.setVal(2, 2);
    t.setVal(6, 1);
    t.setVal(4, 2);
    t.setVal(8, 1);
    t.setVal(9, 2);
    t.setVal(3, 1);

    // print the game to the screen
    t.showGame();


    // print out the winner, if any
    int w = t.winner();
    if(w == 2)
      System.out.println("O wins!");
    else if(w == 1)
      System.out.println("X wins!");
    else if(w == 0)
      System.out.println("This game is a Draw");
    else if(w == -1)
      System.out.println("Game not yet completed!");    

    // reset the board and show it.
    System.out.println("");
    System.out.println("Below is a blank board");
    t.resetGame();
    t.showGame();
  }

}

