Finalphase1 Specsheet
Finalphase1 Specsheet
In this program, you will create a Tic Tac Toe game using the MVC model. There will be a human
player( O ) and computer player( X ) that place game pieces on the game board. The main class should
create objects representing the MVC pattern that play a game of Tic Tac Toe.
Phase 1
Create Class TicTacToeModel
In this class, you will have the game board, symbols, and other methods related to modifying the game
board.
Instance Variables
private Character gameBoard = new Character[3][3]; - game board for tic tac toe
Static Variables
public static final int BOARD_SIZE_WANDL = 3 – width and length size of game board
public static final int WINNING_TOTAL = 3; - amount of matching symbols to win the game
public static final int DRAW_PLAYER = 2; - variable representing a draw condition
public static final int MAX_MOVES = 9; - max moves in a game
public static final Character X = 'X'; - game board piece X, this will be the game piece of player
1(computer).
public static final Character O = 'O'; - game board piece O, this will be the game piece of player
0(human).
public static final Character EMPTY_SPACE = 'E'; - game board piece E to represent empty space
Methods
public TicTacToeModel() - will call an initializeBoard() method.
private void initializeBoard() - will fill the gameBoard with EMPTY_SPACE’s.
public Character getSpace( int column , int row ) - accessor method to get the game piece from the
game board.
public boolean setSpace( int column , int row , int player ) - mutator method to set a game piece to the
game board.
public boolean validatePosition( int column , int row ) - method to validate that the entry is within
bounds and is an empty space.
public Character[][] clone() - clones the gameBoard instance variable.
Methods
public void printGameBoard( Character[][] aGameBoard ) - this will take in a cloned copy of the
game board and will print out the current state of the game board.
public void printWinner( int thePlayer ) - this will print the win or draw message for the player.
Phase 2
Create Class TicTacToeController
In this class, you will place the logic to get update the game board using the TicTacToeModel class.
Static Variables
public static final int HUMAN_PLAYER = 0; - player 0 is human.
public static final int COMPUTER_PLAYER = 1; - player 1 is computer.
public static final int MAX_PLAYERS = 2; - max players for the game.
Instance Variables
private TicTacToeModel gameModel - the game object that will hold the data regarding the game.
private TicTacToeView gameView – the view object that will be responsible for output of the game.
private boolean isThereAWinner - boolean to track whether there is a winner.
private int theWinnerIs - int to track who the winner is.
private int totalMoves - int to track the total number of moves to track draw condition.
private int firstPlayer - int that represents who goes first.
Methods
public TicTacToeController( TicTacToeModel aModel ,TicTacToeView aView ) - 2 arg constructor that
takes in the model and view object and assigns them to the controller instances of the view and model
object. In addition, you will set that there is no winner, set who goes first, and set total moves to 0.
private void setFirstPlayer() - uses Random object to set the player that goes first.
public int getFirstPlayer() - gets who is first to go.
public boolean getIsThereAWinner() - accessor method for whether there is a winner in the game.
public void computersMove() - this method will control how the computer player will move. Will you
make it defensive, offensive, or random?
public void playersMove() - this method will ask the user where you want to place your game piece O
on the board. The method will use a validation method in the model to ensure it is within range and
empty.
public void printGameBoard() - this method will use the view object and pass a copy of the game
board as an argument to the view object’s print game board method.
public void printTheWinner( int thePlayer ) - this method will use the view object and pass the
winning player as an int arugment to the view object’s print winner method.
public int getTheWinnerIs() - this is an accessor method for who the winner is as an int. 0 is human, 1
is computer, and 2 is draw.
public boolean checkForWinner() - this method will check if there is a winning player or draw
condition.