Commit b0e19b0a authored by 9611046's avatar 9611046

made Knight class

parent 1cce88ac
package pieces;
import game.Square;
import java.util.ArrayList;
public class Knight extends Piece {
public Knight(String ID, String imagePath, String color) {
setPieceId(ID);
setImage(imagePath);
setPieceColor(color);
}
public ArrayList<Square> move(Square [][] boardSquares, int x, int y) {
possibleSquares.clear();
int posx[] = {x + 1, x + 1, x + 2, x + 2, x - 1, x - 1, x - 2, x - 2};
int posy[] = {y - 2, y + 2, y - 1, y + 1, y - 2, y + 2, y - 1, y + 1};
for (int i = 0; i < 8; i++)
if ((posx[i] >= 0 && posx[i] < 8 && posy[i] >= 0 && posy[i] < 8))
if ((boardSquares[posx[i]][posy[i]].getPiece() == null || boardSquares[posx[i]][posy[i]].getPiece().getPieceColor() != this.getPieceColor())) {
possibleSquares.add(boardSquares[posx[i]][posy[i]]);
}
return possibleSquares;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment