org.gChess
Class ChessBoard

java.lang.Object
  extended by org.gChess.ChessBoard

public class ChessBoard
extends java.lang.Object

This class is effectively an array of ChessPiece objects. Also included are methods for finding legal moves and moving pieces.


Field Summary
static int COLS
           
static int ROWS
           
 
Constructor Summary
ChessBoard(ChessView view)
          Creates a new chess board with width and height in pixels.
 
Method Summary
 ChessPiece getPieceAt(Location loc)
           
 ChessView getView()
           
 boolean isOccupied(Location loc)
           
 java.util.ArrayList<Location> locsInDirUntilBlocked(Location loc, int direction, int playerColor)
          Grabs locations in a certain direction until it hits something: a wall, a ChessPiece, whatnot.
 void movePiece(ChessPiece cp, Location loc)
          wraps a call to the move method of the chess piece to be moved.
 void putPiece(ChessPiece cp, Location loc)
           
 void remove(Location loc)
           
 ChessSquare squareAtCoords(int x, int y)
          This method WILL RETURN NULL if x,y are not on the board.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROWS

public static final int ROWS
See Also:
Constant Field Values

COLS

public static final int COLS
See Also:
Constant Field Values
Constructor Detail

ChessBoard

public ChessBoard(ChessView view)
Creates a new chess board with width and height in pixels. (so we can fit the screen size)

Parameters:
width -
height -
Method Detail

getView

public ChessView getView()

movePiece

public void movePiece(ChessPiece cp,
                      Location loc)
wraps a call to the move method of the chess piece to be moved.

Parameters:
cp -

remove

public void remove(Location loc)

getPieceAt

public ChessPiece getPieceAt(Location loc)
Parameters:
loc -
Returns:
the ChessPiece at the given Location. null if no ChessPiece at that location

putPiece

public void putPiece(ChessPiece cp,
                     Location loc)

isOccupied

public boolean isOccupied(Location loc)
Parameters:
loc -
Returns:
true if the Location is occupied, false otherwise.

locsInDirUntilBlocked

public java.util.ArrayList<Location> locsInDirUntilBlocked(Location loc,
                                                           int direction,
                                                           int playerColor)
Grabs locations in a certain direction until it hits something: a wall, a ChessPiece, whatnot. If the ChessPiece is on the other "team" it is added to the ArrayList.

Parameters:
loc - - The starting Location
direction - - A member of the direction constants in Location
playerColor - - Either ChessPiece.BLACK or ChessPiece.WHITE
Returns:
ArrayList of Locations that are legal to move to in the given direction.

squareAtCoords

public ChessSquare squareAtCoords(int x,
                                  int y)
This method WILL RETURN NULL if x,y are not on the board. MAKE SURE you check for null values when using this method.

Parameters:
x -
y -
Returns:
ChessSquare containing the coords x,y