Files
chess/Knight.java
2026-04-23 13:10:37 -05:00

25 lines
675 B
Java

import java.util.*;
import javax.swing.ImageIcon;
public class Knight extends Piece {
static int[] xDir = {-1, -2, -2, -1, 1, 2, 2, 1};
static int[] yDir = {-2, -1, 1, 2, 2, 1, -1, -2};
public Knight(int x, int y, String color) {
super(x, y, color, new ImageIcon("sprites/" + color + "/knight.png").getImage());
}
public ArrayList<Position> getLegalMoves(Board board) {
ArrayList<Position> positions = new ArrayList<Position>();
for (int i : xDir) {
for (int j : yDir) {
Position test = new Position(pos.x + i, pos.y + j);
if (!Board.inBounds(test)) continue;
}
}
return positions;
}
}