|
@ -7,6 +7,7 @@ import java.util.ArrayList; |
|
|
|
|
|
|
|
|
public class Chess extends Game { |
|
|
public class Chess extends Game { |
|
|
|
|
|
|
|
|
|
|
|
private int[] firstTurn; |
|
|
private ChessFigure.Team currentTeam; |
|
|
private ChessFigure.Team currentTeam; |
|
|
|
|
|
|
|
|
private ArrayList<ChessFigure> destroyedWhiteFigures; |
|
|
private ArrayList<ChessFigure> destroyedWhiteFigures; |
|
@ -26,6 +27,56 @@ public class Chess extends Game { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void update(String input) { |
|
|
public void update(String input) { |
|
|
|
|
|
outputBuffer.clear(); |
|
|
|
|
|
ArrayList<String> footer = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
if (isFinished()) { |
|
|
|
|
|
resetGame(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int[] coords = convertInput(input); |
|
|
|
|
|
|
|
|
|
|
|
if (coords == null) { |
|
|
|
|
|
footer.add("Invalid Input!"); |
|
|
|
|
|
firstTurn = null; |
|
|
|
|
|
} else { |
|
|
|
|
|
if (firstTurn == null) { |
|
|
|
|
|
firstTurn = coords; |
|
|
|
|
|
if (getChessBoard().getBoard()[firstTurn[1]][firstTurn[0]] != null) { |
|
|
|
|
|
if (getChessBoard().getBoard()[firstTurn[1]][firstTurn[0]].getTeam() == currentTeam) { |
|
|
|
|
|
String firstCoords = (char) (firstTurn[0] + 97) + "" + (firstTurn[1] + 1); |
|
|
|
|
|
footer.add("Currently selected cell: " + firstCoords); |
|
|
|
|
|
} else { |
|
|
|
|
|
footer.add("It's " + currentTeam.name() + "'s turn "); |
|
|
|
|
|
firstTurn = null; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
footer.add("Can't select empty cell"); |
|
|
|
|
|
firstTurn = null; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
footer = makeMove(firstTurn, coords); |
|
|
|
|
|
if(lastFeedback != ChessBoard.MoveFeedback.INVALID && lastFeedback != ChessBoard.MoveFeedback.OUTSIDEOFBOARD) |
|
|
|
|
|
switchCurrentTeam(); |
|
|
|
|
|
firstTurn = null; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (chessBoard.scanForOccurringFigure(ChessFigure.Type.KING, ChessFigure.Team.WHITE) == 0) { |
|
|
|
|
|
footer.add("Black has Won!"); |
|
|
|
|
|
footer.add("Press any key to restart game"); |
|
|
|
|
|
setFinished(true); |
|
|
|
|
|
} |
|
|
|
|
|
if (chessBoard.scanForOccurringFigure(ChessFigure.Type.KING, ChessFigure.Team.BLACK) == 0) { |
|
|
|
|
|
footer.add("White has Won!"); |
|
|
|
|
|
footer.add("Press any key to restart game"); |
|
|
|
|
|
setFinished(true); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
outputBuffer.addAll(getHeader()); |
|
|
|
|
|
outputBuffer.addAll(getUpdatedOutputBoard(destroyedWhiteFigures, destroyedBlackFigures)); |
|
|
|
|
|
outputBuffer.addAll(footer); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -158,11 +209,20 @@ public class Chess extends Game { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void switchCurrentTeam() { |
|
|
|
|
|
if (currentTeam == ChessFigure.Team.WHITE) |
|
|
|
|
|
currentTeam = ChessFigure.Team.BLACK; |
|
|
|
|
|
else |
|
|
|
|
|
currentTeam = ChessFigure.Team.WHITE; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public void resetGame() { |
|
|
public void resetGame() { |
|
|
chessBoard = new ChessBoard(); |
|
|
chessBoard = new ChessBoard(); |
|
|
|
|
|
firstTurn = null; |
|
|
currentTeam = ChessFigure.Team.WHITE; |
|
|
currentTeam = ChessFigure.Team.WHITE; |
|
|
destroyedWhiteFigures = new ArrayList<>(); |
|
|
destroyedWhiteFigures = new ArrayList<>(); |
|
|
destroyedBlackFigures = new ArrayList<>(); |
|
|
destroyedBlackFigures = new ArrayList<>(); |
|
|
|
|
|
setFinished(false); |
|
|
outputBuffer.clear(); |
|
|
outputBuffer.clear(); |
|
|
outputBuffer.addAll(getHeader()); |
|
|
outputBuffer.addAll(getHeader()); |
|
|
outputBuffer.addAll(chessBoard.getOutputBoard()); |
|
|
outputBuffer.addAll(chessBoard.getOutputBoard()); |
|
|