Package Piece
Class Bishop
java.lang.Object
Piece.Piece
Piece.Bishop
Represents a Bishop chess piece with movement logic restricted to diagonals.
This class handles the initialization, rendering, and valid move logic for a bishop. The bishop moves diagonally across the board and can travel any number of tiles as long as its path is unobstructed.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionBishop
(Board board, int col, int row, PieceColor color) Constructs a Bishop 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 bishop.Methods inherited from class Piece.Piece
getColor, paint, readMadeMove, switchMadeMove
-
Constructor Details
-
Bishop
Constructs a Bishop piece at the specified board position and color.Initializes the bishop's coordinates, screen position, name, and sprite based on its color and location on the
Board
.- Parameters:
board
- the board the bishop belongs tocol
- the starting column of the bishoprow
- the starting row of the bishopcolor
- thePieceColor
of the bishop (white or black)
-
-
Method Details
-
isValidMove
Determines whether a move to the specified coordinates is valid for a bishop.A bishop can move any number of tiles diagonally, provided no pieces obstruct the path. This method checks for all four diagonal directions: up-right, up-left, down-right, and down-left.
- 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
-