Package Piece
Class Rook
java.lang.Object
Piece.Piece
Piece.Rook
Represents a Rook chess piece with movement logic restricted to move vertically
or horizontally.
This class handles the initialization, rendering, and valid move logic for a rook. The rook moves vertically or horizontally across the board and can travel any number of tiles as long as its path is unobstructed.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionRook
(Board board, int col, int row, PieceColor color) Constructs a Rook piece at the specified board position and color. -
Method Summary
Modifier and TypeMethodDescriptionboolean
isValidMove
(int toCol, int toRow, Board board) Determines whether a move to the specified coordinates is valid for a Rook.Methods inherited from class Piece.Piece
getColor, paint, readMadeMove, switchMadeMove
-
Constructor Details
-
Rook
Constructs a Rook piece at the specified board position and color.Initializes the rook's coordinates, screen position, name, and sprite based on its color and location on the
Board
.- Parameters:
board
- the board the rook belongs tocol
- the starting column of the rookrow
- the starting row of the rookcolor
- thePieceColor
of the rook (white or black)
-
-
Method Details
-
isValidMove
Determines whether a move to the specified coordinates is valid for a Rook.A rook can move as many tiles vertically or horizontally provided no pieces obstruct the path. This method checks for logic.
- Specified by:
isValidMove
in classPiece
- Parameters:
toCol
- the destination columntoRow
- the destination rowboard
- the current gameBoard
to evaluate piece positions- Returns:
true
if the move is valid;false
otherwise
-