I have provided a program shell that has four functions:
printBoard- Prints the board as shows in the comments at the top of the file.
hasWon - Takes in a player's marker and tells us if that player has won
markTheBoard - marks the given location with the player's marker
isTie - Tells if there are no more spots and no winner
The play starts with X, the variable turn will keep track of who's turn it is.
At the beginning you will display the board with position numbers so the player knows how to place his/her marker.
The code will ask each player where they would like to place their marker until either
there are no more spots to play or one of the players wins.
public class TicTacToe
{
public enum Marker
{
EMPTY,
X,
O
};
private static Marker position1 = Marker.EMPTY;
private static Marker position2 = Marker.EMPTY;
private static Marker position3 = Marker.EMPTY;
private static Marker position4 = Marker.EMPTY;
private static Marker position5 = Marker.EMPTY;
private static Marker position6 = Marker.EMPTY;
private static Marker position7 = Marker.EMPTY;
private static Marker position8 = Marker.EMPTY;
private static Marker position9 = Marker.EMPTY;
private static Marker turn = Marker.X;
public static void main(String[] args)
{
}
/**
* This method will print the board as shown in the above example.
*/
public static void printBoard()
{
}
/**
* Checks if a particular player has won.
*
* @param m The player to check
* @return true if the player won, false if not
*/
public static boolean hasWon(Marker m)
{
}
/**
* Checks if the board is full with no winner
* @return true if the board is full with no winner, false otherwise
*/
public static boolean isTie()
{
}
/**
* Mark the given position with the given marker
* @param m The marker of the player given
* @param pos The position that we are marking
*/
public static void markTheBoard(Marker m, int pos)
{
}
}