Class TicTacToeGame

java.lang.Object
  |
  +--WhiteBlackGame
        |
        +--TicTacToeGame

public class TicTacToeGame
extends WhiteBlackGame

Tic-Tac-Toe Game:
A TicTacToeGame object controls the execution of a game of tic-tac-toe.

Version:
May 18, 2004
Author:
Alyce Brady

Field Summary
protected static java.lang.String BLACK_LABEL
           
protected static java.lang.String WHITE_LABEL
           
 
Constructor Summary
TicTacToeGame()
          Constructs a game for 2 players, "O" and "X".
 
Method Summary
protected  boolean allInARow(int firstRow, int firstCol, int beyondLastRow, int beyondLastCol, int rowIncrement, int colIncrement)
          Returns true if all of the cells in a row, column, or diagonal have been filled by the same player; false otherwise.
 boolean blackWon()
          Returns true if the simulation is over black won; false otherwise.
protected  java.lang.String findWinner()
          Looks for a winner and returns the label of the winner (or a null string if no winner found.
 boolean gameOver()
          Returns true if the game is over; otherwise, returns false.
protected  java.lang.String labelAt(edu.kzoo.grid.Location loc)
          Returns the label of the player at the specified location (or null if no player has marked the specified location).
 void startGame(edu.kzoo.grid.Grid grid)
          Starts or restarts the application.
 boolean whiteWon()
          Returns true if the simulation is over and white won; false otherwise.
 
Methods inherited from class WhiteBlackGame
blackPlayer, getGrid, respondToMousePress, whitePlayer, whitesTurn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WHITE_LABEL

protected static final java.lang.String WHITE_LABEL
See Also:
Constant Field Values

BLACK_LABEL

protected static final java.lang.String BLACK_LABEL
See Also:
Constant Field Values
Constructor Detail

TicTacToeGame

public TicTacToeGame()
Constructs a game for 2 players, "O" and "X".

Method Detail

startGame

public void startGame(edu.kzoo.grid.Grid grid)
Starts or restarts the application.

Overrides:
startGame in class WhiteBlackGame

gameOver

public boolean gameOver()
Returns true if the game is over; otherwise, returns false.

Specified by:
gameOver in class WhiteBlackGame

whiteWon

public boolean whiteWon()
Returns true if the simulation is over and white won; false otherwise.

Specified by:
whiteWon in class WhiteBlackGame

blackWon

public boolean blackWon()
Returns true if the simulation is over black won; false otherwise.


findWinner

protected java.lang.String findWinner()
Looks for a winner and returns the label of the winner (or a null string if no winner found.


allInARow

protected boolean allInARow(int firstRow,
                            int firstCol,
                            int beyondLastRow,
                            int beyondLastCol,
                            int rowIncrement,
                            int colIncrement)
Returns true if all of the cells in a row, column, or diagonal have been filled by the same player; false otherwise.


labelAt

protected java.lang.String labelAt(edu.kzoo.grid.Location loc)
Returns the label of the player at the specified location (or null if no player has marked the specified location).