|
|
@ -7,7 +7,8 @@ import java.util.ArrayList; |
|
|
|
|
|
|
|
public class Chess extends Game { |
|
|
|
|
|
|
|
ChessBoard chessBoard; |
|
|
|
private ChessFigure.Team currentTeam; |
|
|
|
private ChessBoard chessBoard; |
|
|
|
|
|
|
|
public Chess() { |
|
|
|
init(); |
|
|
@ -15,6 +16,7 @@ public class Chess extends Game { |
|
|
|
|
|
|
|
private void init() { |
|
|
|
chessBoard = new ChessBoard(); |
|
|
|
currentTeam = ChessFigure.Team.WHITE; |
|
|
|
outputBuffer.addAll(chessBoard.getOutputBoard()); |
|
|
|
} |
|
|
|
|
|
|
@ -54,6 +56,43 @@ public class Chess extends Game { |
|
|
|
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) { |
|
|
|
ArrayList<String> result = new ArrayList<>(); |
|
|
|
String line = ""; |
|
|
@ -77,4 +116,12 @@ public class Chess extends Game { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public ChessBoard getChessBoard() { |
|
|
|
return this.chessBoard; |
|
|
|
} |
|
|
|
|
|
|
|
public ChessFigure.Team getCurrentTeam() { |
|
|
|
return this.currentTeam; |
|
|
|
} |
|
|
|
|
|
|
|
} |