Browse Source

Added getUpdatedOutputBoard

feature-chess
Dion Aliu 3 years ago
parent
commit
8eeeb84301
  1. 37
      src/main/java/Game/Chess.java

37
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<ChessFigure> destroyedWhiteFigures;
private ArrayList<ChessFigure> 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<String> getUpdatedOutputBoard(ArrayList<ChessFigure> whiteFigures, ArrayList<ChessFigure> blackFigures) {
ArrayList<String> updatedOutputBoard = chessBoard.getOutputBoard();
ArrayList<String> sidebarWhiteFigures = getSidebarFigures(whiteFigures, 5);
ArrayList<String> 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<String> getSidebarFigures(ArrayList<ChessFigure> chessFigureArrayList, int maxPerLine) {
ArrayList<String> result = new ArrayList<>();
String line = "";
@ -124,4 +153,12 @@ public class Chess extends Game {
return this.currentTeam;
}
public ArrayList<ChessFigure> getDestroyedWhiteFigures() {
return destroyedWhiteFigures;
}
public ArrayList<ChessFigure> getDestroyedBlackFigures() {
return destroyedBlackFigures;
}
}
Loading…
Cancel
Save