diff --git a/src/main/java/Game/Chess.java b/src/main/java/Game/Chess.java index d6fef15..91fdf86 100644 --- a/src/main/java/Game/Chess.java +++ b/src/main/java/Game/Chess.java @@ -8,6 +8,10 @@ import java.util.ArrayList; public class Chess extends Game { private ChessFigure.Team currentTeam; + + private ArrayList destroyedWhiteFigures; + private ArrayList destroyedBlackFigures; + private ChessBoard chessBoard; public Chess() { @@ -17,6 +21,8 @@ public class Chess extends Game { private void init() { chessBoard = new ChessBoard(); currentTeam = ChessFigure.Team.WHITE; + destroyedWhiteFigures = new ArrayList<>(); + destroyedBlackFigures = new ArrayList<>(); outputBuffer.addAll(chessBoard.getOutputBoard()); } @@ -76,6 +82,10 @@ public class Chess extends Game { result.add("Successfully moved " + sourceFigureName.toLowerCase() + " from " + sourceCoords + " to " + targetCoords); } else if (moveFeedback == ChessBoard.MoveFeedback.ENEMYBEATEN) { result.add(sourceFigureName + " successfully beat " + targetFigureName.toLowerCase() + " at " + targetCoords); + if (targetFigure.getTeam() == ChessFigure.Team.WHITE) + getDestroyedWhiteFigures().add(targetFigure); + else + getDestroyedBlackFigures().add(targetFigure); } else { result.add("Invalid input!"); switch (moveFeedback) { @@ -93,6 +103,25 @@ public class Chess extends Game { return result; } + private ArrayList getUpdatedOutputBoard(ArrayList whiteFigures, ArrayList blackFigures) { + ArrayList updatedOutputBoard = chessBoard.getOutputBoard(); + ArrayList sidebarWhiteFigures = getSidebarFigures(whiteFigures, 5); + ArrayList sidebarBlackFigures = getSidebarFigures(blackFigures, 5); + + for (int i = 0; i < sidebarWhiteFigures.size(); i++) { + int index = i + 3; + updatedOutputBoard.set(index, updatedOutputBoard.get(index) + sidebarWhiteFigures.get(i)); + } + + for (int i = 0; i < sidebarBlackFigures.size(); i++) { + int index = updatedOutputBoard.size() - (i + 3); + updatedOutputBoard.set(index, updatedOutputBoard.get(index) + sidebarBlackFigures.get(i)); + } + + + return updatedOutputBoard; + } + public ArrayList getSidebarFigures(ArrayList chessFigureArrayList, int maxPerLine) { ArrayList result = new ArrayList<>(); String line = ""; @@ -124,4 +153,12 @@ public class Chess extends Game { return this.currentTeam; } + public ArrayList getDestroyedWhiteFigures() { + return destroyedWhiteFigures; + } + + public ArrayList getDestroyedBlackFigures() { + return destroyedBlackFigures; + } + }