Class TicTacToeModel

java.lang.Object
  |
  +--GameModel
        |
        +--TicTacToeModel
All Implemented Interfaces:
java.lang.Cloneable, GameStatusConstants, LastMoveStatusConstants, StatusInfo

public class TicTacToeModel
extends GameModel
implements StatusInfo, java.lang.Cloneable

This is the model for the TicTacToe game. It handles all the data involved in playing the game of tic tac toe which consists of trying to create a row, column or diagonal of x's or o's


Fields inherited from class GameModel
myGameName, myGamePieces, myGameStatus, myLastMoveStatus, myPlayingBoard
 
Fields inherited from interface GameStatusConstants
GAME_IN_PROGRESS, GAME_LOST, GAME_OVER, GAME_TIED, GAME_WON
 
Fields inherited from interface LastMoveStatusConstants
MOVE_SUCCESSFUL, MOVE_UNSUCCESSFUL
 
Method Summary
 java.lang.Object clone()
          allows a new model to be created fo the gui
 boolean colWin()
          Return true if a column of 3 of the same pieces has been created
 boolean diagonalWin()
          Return true if a diagonal of three of the same elements has been created
 javax.swing.JComponent getStatusDisplay()
           
 boolean isGameOver()
          return true if game is over/tied.
 boolean isGameWon()
          return true if a row, column, or diagonal of 3 of the same elements has been created
 boolean isValid(int col, int row)
          returns true if there is no gamepiece at the specified row and column
 void move(int col, int row, GamePiece p)
          sets the current player's gamepiece to the specified row and column of the board if there is no other piece at that location
 void newGame()
          Creates a new playingboard, initializes status variables and sets game pieces on board
 void processClick(int col, int row)
          on click move currentgame piece at clicked col and row
 boolean rowWin()
          check if a row of 3 of the same pieces has been created
 void setGamePieces()
          set the gamepieces to be used in the game
 void updateGameStatus()
          update the status of the game, set status variables that determine if game is won tied or still in progress
 
Methods inherited from class GameModel
getBoardHeight, getBoardWidth, getGameName, getGamePieceAt, getGameStatus, getLastMoveStatus, getPlayingBoard, hasGamePieceAt, isGameLost, isGameTied, processClick, setGamePieceAt, wasLastMoveSuccessful
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newGame

public void newGame()
Creates a new playingboard, initializes status variables and sets game pieces on board
Overrides:
newGame in class GameModel

isValid

public boolean isValid(int col,
                       int row)
returns true if there is no gamepiece at the specified row and column

move

public void move(int col,
                 int row,
                 GamePiece p)
sets the current player's gamepiece to the specified row and column of the board if there is no other piece at that location

updateGameStatus

public void updateGameStatus()
update the status of the game, set status variables that determine if game is won tied or still in progress
Overrides:
updateGameStatus in class GameModel

isGameWon

public boolean isGameWon()
return true if a row, column, or diagonal of 3 of the same elements has been created
Overrides:
isGameWon in class GameModel
Following copied from class: GameModel
Returns:
true if the game has been won, false otherwise

isGameOver

public boolean isGameOver()
return true if game is over/tied.
Overrides:
isGameOver in class GameModel
Following copied from class: GameModel
Returns:
false if the game is still in progress, true otherwise

rowWin

public boolean rowWin()
check if a row of 3 of the same pieces has been created

colWin

public boolean colWin()
Return true if a column of 3 of the same pieces has been created

diagonalWin

public boolean diagonalWin()
Return true if a diagonal of three of the same elements has been created

processClick

public void processClick(int col,
                         int row)
on click move currentgame piece at clicked col and row
Overrides:
processClick in class GameModel
Following copied from class: GameModel
Parameters:
col - is the number of the column that the click occurred
row - is the number of the row that the click occurred

setGamePieces

public void setGamePieces()
set the gamepieces to be used in the game

getStatusDisplay

public javax.swing.JComponent getStatusDisplay()
Specified by:
getStatusDisplay in interface StatusInfo

clone

public java.lang.Object clone()
allows a new model to be created fo the gui
Overrides:
clone in class GameModel
Following copied from class: GameModel
Returns:
a copy of the GameModel