Package Piece
Class Knight
java.lang.Object
Piece.Piece
Piece.Knight
Represents a Knight chess piece with movement logic in an "L" shape directed on the
chess board.
This class handles the initialization, rendering, and valid move logic for a knight. The knight moves in an "L" shape restricted to 2 squares in one direction (either vertically or horizontally) and then 1 square perpendicularly to that direction on the chess board.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionKnight
(Board board, int col, int row, PieceColor color) Constructs a Knight 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 Knight.Methods inherited from class Piece.Piece
getColor, paint, readMadeMove, switchMadeMove
-
Constructor Details
-
Knight
Constructs a Knight piece at the specified board position and color.Initializes the knight's coordinates, screen position, name, and sprite based on its color and location on the
Board
.- Parameters:
board
- the board the knight belongs tocol
- the starting column of the knightrow
- the starting row of the knightcolor
- thePieceColor
of the knight (white or black)
-
-
Method Details
-
isValidMove
Determines whether a move to the specified coordinates is valid for a Knight.A knight can move in an "L" shape restricted to 2 squares in tne direction (either vertically or horizontally) and then 1 square perpendicularly to that direction on the chess board. 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
-