modify the setPiece method to make it remove any piece that was already
there first
This commit is contained in:
parent
709e41c360
commit
b702e97e27
|
|
@ -33,6 +33,15 @@ public class Board {
|
|||
}
|
||||
|
||||
public void setPiece(boolean isWhite, PieceType type, int x, int y) {
|
||||
// 1. remove any piece that was already in this cell
|
||||
for (int i = 0; i < pieces.size(); i++) {
|
||||
Piece p = pieces.get(i);
|
||||
if(p.getX() == x && p.getY() == y) {
|
||||
pieces.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 2. add the new piece
|
||||
pieces.add(new Piece(x,y,type,isWhite));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue