model.pieces
Class Piece

java.lang.Object
  extended by model.pieces.Piece
Direct Known Subclasses:
Bishop, King, Knight, Pawn, Queen, Rook

public abstract class Piece
extends java.lang.Object

Represents a Piece in the chess board.


Constructor Summary
Piece(java.lang.String pieceName, boolean what, javax.swing.Icon icon)
          This constructor is used by all the subclasses of Piece.
 
Method Summary
 boolean getColor()
          accessor(selector): Returns the Color of the given Piece.
 javax.swing.Icon getIcon()
          accessor(selector): Returns an icon of the Piece.
 java.lang.String getName()
          accessor(selector): Returns the name of the given Piece.
abstract  java.util.List<Move> moves(Cell x, ChessBoard z)
          Finds and returns all the possible moves of the Piece in the given Cell, in the given ChessBoard.
 void setIcon(javax.swing.Icon r)
          transformer(mutative): Changes the Icon of the given piece with the one passed as parameter.
 void setName(java.lang.String x)
          transformer(mutative): Changes the Piece's name to the String passed as parameter.
 java.lang.String toString()
          accessor(selector): Returns a String representation of a Piece.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Piece

public Piece(java.lang.String pieceName,
             boolean what,
             javax.swing.Icon icon)
      throws java.lang.IllegalArgumentException
This constructor is used by all the subclasses of Piece.
constructor: Constructs a Piece with the given parameters.
precondition: pieceName parameter cannot be null or empty.
postcondition: Creates a new Piece

Parameters:
pieceName - the String name of the piece
what - the Color the given piece will have
icon - the Icon this piece will have
Throws:
IllegalArgument - exception if pieceName parameter is empty or null.
java.lang.IllegalArgumentException
Method Detail

getColor

public boolean getColor()
accessor(selector): Returns the Color of the given Piece.
postcondition: Returns the Color of the Piece(true for white, false for black)

Returns:
the Color of the given Piece

moves

public abstract java.util.List<Move> moves(Cell x,
                                           ChessBoard z)
Finds and returns all the possible moves of the Piece in the given Cell, in the given ChessBoard.
postcondition: Creates and returns a List of all the possible moves of the Piece in the given Cell. In case the Cell doesn't contain a Piece, an empty list is returned
.

Parameters:
x - Piece's current Cell
z - ChessBoard where the Cell can be found
Returns:
All the possible moves of the Piece in this particular Cell.

setIcon

public void setIcon(javax.swing.Icon r)
transformer(mutative): Changes the Icon of the given piece with the one passed as parameter.
postcondition: Changes current Piece Icon with the one given.

Parameters:
r - Icon to be set to.

getIcon

public javax.swing.Icon getIcon()
accessor(selector): Returns an icon of the Piece.
postcondition: Returns the icon of a Piece depending on it's color.

Returns:
Icon, an image of the Piece.

setName

public void setName(java.lang.String x)
             throws java.lang.NullPointerException,
                    java.lang.IllegalArgumentException
transformer(mutative): Changes the Piece's name to the String passed as parameter.
precondition: x is not null and not the empty String.
postcondition: Changes the name of the Piece to the argument one.

Parameters:
x - String Parameter to alter Player's name to.
Throws:
java.lang.NullPointerException - If String argument x is null.
java.lang.IllegalArgumentException - If the String is empty

getName

public java.lang.String getName()
accessor(selector): Returns the name of the given Piece.
postcondition: Returns the name of the given Piece

Returns:
String name of the Piece

toString

public java.lang.String toString()
accessor(selector): Returns a String representation of a Piece.
postcondition: Returns a String display of a Piece.

Overrides:
toString in class java.lang.Object
Returns:
a String symbolizing the Piece.