1
0
forked from pabulaner/vivi
vivi-exercises/chess/pieces/Piece.java
2025-05-20 09:17:32 +02:00

71 lines
1.6 KiB
Java

package de.vivi.chess.pieces;
import de.vivi.chess.board.Board;
import de.vivi.chess.board.Field;
public abstract class Piece {
Color color;
private Type type;
protected char symbol;
protected Field field;
protected Piece(Color color, Type type) {
this.color = color;
this.type = type;
symbol = '\u0000';
}
protected Piece(Color color, Field field) {
this.color = color;
this.field = field;
}
protected Piece(Color color, Type type, Field field) {
this.color = color;
this.type = type;
this.field = field;
}
/**
* TODO: implement
* <p>
* This method needs to be implemented in each piece by
* using inheritance. It returns true if the move from the
* from field to the to field is considered a valid move
* for the type of piece this method is called on. Otherwise
* it returns false.
*/
public abstract boolean isValidMove(Board board, Field from, Field to);
public Color getColor() {
// TODO: implement
return color;
}
public Type getType() {
// TODO: implement
return type;
}
/**
* TODO: implement
* <p>
* Use unicode symbols for the chess pieces. You can find
* them here:
* <a href="https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode">Unicode chess pieces</a>
*/
public char getSymbol() {
return symbol;
}
public Field getField() {
return field;
}
public void setField(Field field) {
this.field = field;
}
}