57 lines
1.6 KiB
Java
57 lines
1.6 KiB
Java
package de.vivi.chess.pieces;
|
|
|
|
import de.vivi.chess.board.Board;
|
|
import de.vivi.chess.board.Field;
|
|
|
|
public class Pawn extends Piece {
|
|
|
|
private boolean isValid = false;
|
|
|
|
public Pawn(Color color, Type type) {
|
|
super(color, type);
|
|
}
|
|
|
|
@Override
|
|
public char getSymbol() {
|
|
if (getColor() == Color.WHITE) {
|
|
if (getType() == Type.PAWN) {
|
|
symbol = '\u265F';
|
|
}
|
|
|
|
} else if (getColor() == Color.BLACK) {
|
|
if (getType() == Type.PAWN) {
|
|
symbol = '\u2659';
|
|
}
|
|
}
|
|
return symbol;
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidMove(Board board, Field from, Field to) {
|
|
if (board.getPiece(from).getSymbol() == symbol &&
|
|
board.getPiece(from).getColor() == Color.WHITE) {
|
|
|
|
if (board.getPiece(to) == null) {
|
|
if (from.getRow() == 6 && to.getRow() == 4) {
|
|
isValid = true;
|
|
} else if (from.getRow() == 6 && to.getRow() == 5) {
|
|
isValid = true;
|
|
}
|
|
}
|
|
|
|
} else if (board.getPiece(from).getSymbol() == symbol &&
|
|
board.getPiece(from).getColor() == Color.BLACK) {
|
|
if (board.getPiece(to) == null) {
|
|
if (from.getRow() == 1 && to.getRow() == 2) {
|
|
isValid = true;
|
|
} else if (from.getRow() == 1 && to.getRow() == 3) {
|
|
isValid = true;
|
|
}
|
|
}
|
|
} else {
|
|
isValid = false;
|
|
}
|
|
return isValid;
|
|
}
|
|
}
|