reversi
Class TextGameBoard

java.lang.Object
  |
  +--reversi.TextGameBoard
All Implemented Interfaces:
GameBoard, java.io.Serializable

public class TextGameBoard
extends java.lang.Object
implements GameBoard

A class to handle all actions related to the Reversi Game Board. It provides useful methods for the Game Controller to call. @see ReversiGame

See Also:
Serialized Form

Fields inherited from interface reversi.GameBoard
EMPTY, GREEN, RED
 
Constructor Summary
TextGameBoard()
          Constructor needs the specific Canvas to call its drawing methods.
 
Method Summary
 boolean checkMove(int player, Coordinates c)
          This method checks whether a given move would be valid.
 int countStones(int player)
          Counts the number of pieces for the given player.
 int getPosition(Coordinates c)
          This method gives access to the player to find out the status of the game board.
protected  int getPosition(int x, int y)
          Same as other, but with x and y instead.
 int getSize()
          Method implementing the interface @see GameBoard.
 boolean isFull()
          Checks whether the board is already full.
 boolean isMoveAvailable(int player)
          This method returns true if there is at least one possible move for player and false if he has to pass.
 void makeMove(int player, Coordinates c)
          This method sets the piece for the given player and updates the board by flipping all possible of the opponent's pieces.
 java.lang.String toString()
           
 void updateBoard(GameBoard gb)
          Clone the situation of the board.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextGameBoard

public TextGameBoard()
Constructor needs the specific Canvas to call its drawing methods.
Parameters:
c - An instance of @see ReversiCanvas.
Method Detail

getSize

public int getSize()
Method implementing the interface @see GameBoard.
Specified by:
getSize in interface GameBoard

updateBoard

public void updateBoard(GameBoard gb)
Clone the situation of the board.

getPosition

public int getPosition(Coordinates c)
                throws OutOfBoundsException
This method gives access to the player to find out the status of the game board.
Specified by:
getPosition in interface GameBoard
Parameters:
c - The Coordinates for the board.
Returns:
Either GameBoard.RED, GameBoard.GREEN or GameBoard.EMPTY.
Throws:
-  

getPosition

protected int getPosition(int x,
                          int y)
Same as other, but with x and y instead. Does not throw an @see OutOfBoundsException.

isMoveAvailable

public boolean isMoveAvailable(int player)
This method returns true if there is at least one possible move for player and false if he has to pass.
Parameters:
player - Specifies the color of the player, either GameBoard.RED or GameBoard.GREEN.
Returns:
True if the player has at least one possible move.

checkMove

public boolean checkMove(int player,
                         Coordinates c)
This method checks whether a given move would be valid. To be called before makeMove().
Parameters:
player - The player, either GameBoard.RED or GameBoard.GREEN.
c - The Coordinates to be checked.
Returns:
true if the move is valid for the player.

makeMove

public void makeMove(int player,
                     Coordinates c)
This method sets the piece for the given player and updates the board by flipping all possible of the opponent's pieces. Assumes checkMove() has been called.
Parameters:
player - The player, either GameBoard.RED or GameBoard.GREEN.
c - The Coordinates where to put the piece for the given player.

isFull

public boolean isFull()
Checks whether the board is already full.
Returns:
true if the board is full, false otherwise.

countStones

public int countStones(int player)
Counts the number of pieces for the given player.
Parameters:
player - The color of the pieces for the player to count, either GameBoard.RED or GameBoard.GREEN.
Returns:
The number of pieces on the board for the given player.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object