|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgame.Board
Board represents the state of a checkerboard. A checkerboard is a square array of squares. Although checkerboards are normally 8x8, Board can represent any size checkerboard.
Each square of the checkboard may contain at most one Piece, or it may be empty. Each square is identified by its row and column, numbered from 0 to size-1.
Boards are mutable: pieces can be added, removed, and moved. The board informs a set of listeners about these mutations. The size of a board is immutable, however.
Constructor Summary | |
Board(int n)
Make an empty n x n checkerboard. |
Method Summary | |
void |
add(Piece piece,
int row,
int col)
Add a new piece to this board. |
void |
addBoardListener(BoardListener listener)
Add a listener to this board. |
void |
clear()
Remove all pieces from board. |
PieceLocation |
find(Piece piece)
Get a piece's location on this board. |
Piece |
getPieceAt(int row,
int col)
Get the piece found at a given row and column. |
int |
getSize()
Get the size of the checkerboard. |
boolean |
isEmpty(int row,
int col)
Test if a square contains a piece. |
void |
move(Piece piece,
int toRow,
int toCol)
Move a piece from its current square on this board to a new square. |
Iterator |
pieceLocations()
Get all pieces on this board, with their locations. |
Iterator |
pieces()
Get all pieces on this board. |
void |
remove(Piece piece)
Remove a piece from this board. |
void |
removeBoardListener(BoardListener listener)
Remove a listener from this board. |
String |
toString()
Converts board to a string representation. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Board(int n)
n
- number of squares on each side of the checkerboardMethod Detail |
public int getSize()
public Piece getPieceAt(int row, int col)
row
- row number in range [0,size-1]col
- column number in range [0,size-1]
public boolean isEmpty(int row, int col)
row
- row number in range [0,size-1]col
- column number in range [0,size-1]
public PieceLocation find(Piece piece)
piece
- Piece to find
public Iterator pieces()
public Iterator pieceLocations()
public void add(Piece piece, int row, int col)
piece
- Piece to add, not already found on this boardrow
- row number in range [0,size-1]col
- column number in range [0,size-1]public void move(Piece piece, int toRow, int toCol)
piece
- Piece to move, which must already be found on
this board.toRow
- row number in range [0,size-1]toCol
- column number in range [0,size-1]public void remove(Piece piece)
piece
- Piece to remove, which must be found on this boardpublic void clear()
public void addBoardListener(BoardListener listener)
listener
- Listener to addpublic void removeBoardListener(BoardListener listener)
listener
- Listener to removepublic String toString()
. . . . . . . . . . . . . . . .Each piece on the board is represented by its toString representation.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |