|
@ -8,6 +8,10 @@ import java.util.ArrayList; |
|
|
public class Chess extends Game { |
|
|
public class Chess extends Game { |
|
|
|
|
|
|
|
|
private ChessFigure.Team currentTeam; |
|
|
private ChessFigure.Team currentTeam; |
|
|
|
|
|
|
|
|
|
|
|
private ArrayList<ChessFigure> destroyedWhiteFigures; |
|
|
|
|
|
private ArrayList<ChessFigure> destroyedBlackFigures; |
|
|
|
|
|
|
|
|
private ChessBoard chessBoard; |
|
|
private ChessBoard chessBoard; |
|
|
|
|
|
|
|
|
public Chess() { |
|
|
public Chess() { |
|
@ -17,6 +21,8 @@ public class Chess extends Game { |
|
|
private void init() { |
|
|
private void init() { |
|
|
chessBoard = new ChessBoard(); |
|
|
chessBoard = new ChessBoard(); |
|
|
currentTeam = ChessFigure.Team.WHITE; |
|
|
currentTeam = ChessFigure.Team.WHITE; |
|
|
|
|
|
destroyedWhiteFigures = new ArrayList<>(); |
|
|
|
|
|
destroyedBlackFigures = new ArrayList<>(); |
|
|
outputBuffer.addAll(chessBoard.getOutputBoard()); |
|
|
outputBuffer.addAll(chessBoard.getOutputBoard()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -76,6 +82,10 @@ public class Chess extends Game { |
|
|
result.add("Successfully moved " + sourceFigureName.toLowerCase() + " from " + sourceCoords + " to " + targetCoords); |
|
|
result.add("Successfully moved " + sourceFigureName.toLowerCase() + " from " + sourceCoords + " to " + targetCoords); |
|
|
} else if (moveFeedback == ChessBoard.MoveFeedback.ENEMYBEATEN) { |
|
|
} else if (moveFeedback == ChessBoard.MoveFeedback.ENEMYBEATEN) { |
|
|
result.add(sourceFigureName + " successfully beat " + targetFigureName.toLowerCase() + " at " + targetCoords); |
|
|
result.add(sourceFigureName + " successfully beat " + targetFigureName.toLowerCase() + " at " + targetCoords); |
|
|
|
|
|
if (targetFigure.getTeam() == ChessFigure.Team.WHITE) |
|
|
|
|
|
getDestroyedWhiteFigures().add(targetFigure); |
|
|
|
|
|
else |
|
|
|
|
|
getDestroyedBlackFigures().add(targetFigure); |
|
|
} else { |
|
|
} else { |
|
|
result.add("Invalid input!"); |
|
|
result.add("Invalid input!"); |
|
|
switch (moveFeedback) { |
|
|
switch (moveFeedback) { |
|
@ -93,6 +103,25 @@ public class Chess extends Game { |
|
|
return result; |
|
|
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) { |
|
|
public ArrayList<String> getSidebarFigures(ArrayList<ChessFigure> chessFigureArrayList, int maxPerLine) { |
|
|
ArrayList<String> result = new ArrayList<>(); |
|
|
ArrayList<String> result = new ArrayList<>(); |
|
|
String line = ""; |
|
|
String line = ""; |
|
@ -124,4 +153,12 @@ public class Chess extends Game { |
|
|
return this.currentTeam; |
|
|
return this.currentTeam; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ArrayList<ChessFigure> getDestroyedWhiteFigures() { |
|
|
|
|
|
return destroyedWhiteFigures; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ArrayList<ChessFigure> getDestroyedBlackFigures() { |
|
|
|
|
|
return destroyedBlackFigures; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |