//12/14/2014
//The purpose of this program is to play a tic tac toe game against the computer
//The TicTacToe class.
import java.awt.*;
import java.io.*;
import java.util.*;
public class TicTacToe
{
public static char DrawBoard (char [] [] Board) //DrawBoard Method
{
char DrawBoard = '-' ;
System.out.println("-------------");
for (int row = 0 ; row < 3 ; row = row + 1)
{
System.out.print ("| ") ;
for (int column = 0 ; column < 3 ; column = column + 1)
{
System.out.print (Board [row] [column] + " | ") ;
DrawBoard = Board [row] [column] ;
}
System.out.println () ;
System.out.println ("-------------") ;
}
return (DrawBoard) ;
}
//public static int Winner () //Winner Method
//{
//}
public static void main (String[] args)
{
//Variable declaration
Scanner kbReader = new Scanner(System.in);
char [] [] Board = new char [3] [3] ;
String MenuInput ;
int BoardOutput ;
//Welcome
System.out.println ("Welcome to Tic Tac Toe game!.") ;
System.out.println ("") ;
System.out.println ("If you wish to play, type 'Play'") ;
System.out.println ("If you wish to read the instructions, type 'Instructions'") ;
System.out.println ("If you wish to exit, type 'Exit'") ;
MenuInput = kbReader.next () ;
if (MenuInput.equals ("Play") || MenuInput.equals ("play"))
{
System.out.println ("\f") ;
System.out.println (" Tic Tac Toe") ;
BoardOutput = DrawBoard (Board) ;
System.out.println ("Please enter the coordinates you wish to place your move.") ;
}
else if (MenuInput.equals ("Instructions") || MenuInput.equals ("instructions"))
{
System.out.println ("\f") ;
System.out.println ("You will be playing the game of Tic Tac Toe against the computer.") ;
System.out.println ("The object of this game is to get three of your own x's or o's in a line.") ;
System.out.println ("You take turns placing the x's and o's and whoever gets three in a row first wins.") ;
System.out.println ("Good Luck!") ;
System.out.println ("") ;
System.out.println ("If you wish to play, type 'Play'") ;
System.out.println ("If you wish to exit, type 'Exit'") ;
MenuInput = kbReader.next () ;
}
else if (MenuInput.equals ("Exit") || MenuInput.equals ("exit"))
{
System.out.println ("Thank you for using Tic Tac Toe game!") ;
System.exit (0) ;
}
else
{
System.out.println ("Sorry, that is not a valid choice.") ;
System.out.println ("If you wish to play, type 'Play'") ;
System.out.println ("If you wish to read the instructions, type 'Instructions'") ;
System.out.println ("If you wish to exit, type 'Exit'") ;
MenuInput = kbReader.next () ;
}
} // main method
} // TicTacToe class
|