Implemented the capability of copying pieces from another piece. Prevents pass by reference.

This commit is contained in:
Jonathan Turner 2024-02-03 11:50:55 -05:00
parent 56294257de
commit c5687291be

View File

@ -25,11 +25,26 @@ public class Piece {
if (value < 1 || value > 8) { if (value < 1 || value > 8) {
throw new IllegalArgumentException("The piece value is not valid. Valid Range: 1 <= Value <= 8"); throw new IllegalArgumentException("The piece value is not valid. Valid Range: 1 <= Value <= 8");
} }
this.setLoc(loc); this.setLoc(loc);
this.value = value; this.value = value;
} }
/**
* Creates a new piece from an existing piece.
*
* @precondition piece != null
* @postcondition a copied piece is created.
*
* @param piece the piece being copied
*/
public Piece(Piece piece) {
if (piece == null) {
throw new IllegalArgumentException("The piece cannot be null.");
}
this.loc = piece.getLoc();
this.value = piece.getValue();
}
/** /**
* Moves the piece to a new location. * Moves the piece to a new location.
* *