|
@ -7,7 +7,8 @@ import java.util.ArrayList; |
|
|
|
|
|
|
|
|
public class Chess extends Game { |
|
|
public class Chess extends Game { |
|
|
|
|
|
|
|
|
ChessBoard chessBoard; |
|
|
|
|
|
|
|
|
private ChessFigure.Team currentTeam; |
|
|
|
|
|
private ChessBoard chessBoard; |
|
|
|
|
|
|
|
|
public Chess() { |
|
|
public Chess() { |
|
|
init(); |
|
|
init(); |
|
@ -15,6 +16,7 @@ public class Chess extends Game { |
|
|
|
|
|
|
|
|
private void init() { |
|
|
private void init() { |
|
|
chessBoard = new ChessBoard(); |
|
|
chessBoard = new ChessBoard(); |
|
|
|
|
|
currentTeam = ChessFigure.Team.WHITE; |
|
|
outputBuffer.addAll(chessBoard.getOutputBoard()); |
|
|
outputBuffer.addAll(chessBoard.getOutputBoard()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -54,20 +56,57 @@ public class Chess extends Game { |
|
|
return temp; |
|
|
return temp; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ArrayList<String> makeMove(int[] source, int[] target) { |
|
|
|
|
|
ArrayList<String> result = new ArrayList<>(); |
|
|
|
|
|
ChessFigure sourceFigure = chessBoard.getBoard()[source[1]][source[0]]; |
|
|
|
|
|
ChessFigure targetFigure = chessBoard.getBoard()[target[1]][target[0]]; |
|
|
|
|
|
String sourceFigureName = "<NOT FOUND>"; |
|
|
|
|
|
String targetFigureName = "<NOT FOUND>"; |
|
|
|
|
|
String sourceCoords = (char) (source[0] + 97) + "" + (source[1] + 1); |
|
|
|
|
|
String targetCoords = (char) (target[0] + 97) + "" + (target[1] + 1); |
|
|
|
|
|
|
|
|
|
|
|
ChessBoard.MoveFeedback moveFeedback = chessBoard.moveFigure(source[0], source[1], target[0], target[1]); |
|
|
|
|
|
|
|
|
|
|
|
if (sourceFigure != null) |
|
|
|
|
|
sourceFigureName = sourceFigure.getTeam().name().toCharArray()[0] + sourceFigure.getTeam().name().substring(1).toLowerCase() + " " + sourceFigure.getType().name().toLowerCase(); |
|
|
|
|
|
if (targetFigure != null) |
|
|
|
|
|
targetFigureName = targetFigure.getTeam().name().toLowerCase() + " " + targetFigure.getType().name().toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
if (moveFeedback == ChessBoard.MoveFeedback.MOVE) { |
|
|
|
|
|
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); |
|
|
|
|
|
} else { |
|
|
|
|
|
result.add("Invalid input!"); |
|
|
|
|
|
switch (moveFeedback) { |
|
|
|
|
|
case INVALID: |
|
|
|
|
|
if (chessBoard.getBoard()[target[0]][target[1]].getTeam() == getCurrentTeam()) |
|
|
|
|
|
result.add("You are on the same Team! [" + getCurrentTeam().name() + "]"); |
|
|
|
|
|
break; |
|
|
|
|
|
case OUTSIDEOFBOARD: |
|
|
|
|
|
result.add("Input is not inside the board!"); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
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 = ""; |
|
|
int counter = 0; |
|
|
int counter = 0; |
|
|
|
|
|
|
|
|
for(int i = 0; i < chessFigureArrayList.size(); i++){ |
|
|
|
|
|
if(i == chessFigureArrayList.size() - 1) { |
|
|
|
|
|
|
|
|
for (int i = 0; i < chessFigureArrayList.size(); i++) { |
|
|
|
|
|
if (i == chessFigureArrayList.size() - 1) { |
|
|
line += chessFigureArrayList.get(i).getSymbol() + ""; |
|
|
line += chessFigureArrayList.get(i).getSymbol() + ""; |
|
|
result.add(line); |
|
|
result.add(line); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
line += chessFigureArrayList.get(i).getSymbol() + ","; |
|
|
line += chessFigureArrayList.get(i).getSymbol() + ","; |
|
|
counter++; |
|
|
counter++; |
|
|
if(counter >= maxPerLine) { |
|
|
|
|
|
|
|
|
if (counter >= maxPerLine) { |
|
|
result.add(line); |
|
|
result.add(line); |
|
|
line = ""; |
|
|
line = ""; |
|
|
counter = 0; |
|
|
counter = 0; |
|
@ -77,4 +116,12 @@ public class Chess extends Game { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ChessBoard getChessBoard() { |
|
|
|
|
|
return this.chessBoard; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ChessFigure.Team getCurrentTeam() { |
|
|
|
|
|
return this.currentTeam; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |