import java.util.*; import javax.swing.ImageIcon; public class Bishop extends Piece { boolean hasMoved; public Bishop(int x, int y, String color) { super(x, y, color, new ImageIcon("sprites/" + color + "/bishop.png").getImage()); hasMoved = false; } public ArrayList getLegalMoves(Board board) { ArrayList positions = new ArrayList(); // check left for (int i = pos.x - 1; i >= 0; i--) { Position test = new Position(i, pos.y); if (board.isOpen(test)) { positions.add(test); continue; } else if (board.getPiece(test).colorMatches(this)) { break; } else { positions.add(test); break; } } // check right for (int i = pos.x + 1; i <= 7; i++) { Position test = new Position(i, pos.y); if (board.isOpen(test)) { positions.add(test); continue; } else if (board.getPiece(test).colorMatches(this)) { break; } else { positions.add(test); break; } } // check up for (int i = pos.y + 1; i <= 7; i++) { Position test = new Position(pos.x, i); if (board.isOpen(test)) { positions.add(test); continue; } else if (board.getPiece(test).colorMatches(this)) { break; } else { positions.add(test); break; } } // check down for (int i = pos.y - 1; i >= 0; i--) { Position test = new Position(pos.x, i); if (board.isOpen(test)) { positions.add(test); continue; } else if (board.getPiece(test).colorMatches(this)) { break; } else { positions.add(test); break; } } return positions; } }