Browse Source

Added getOutput method and helper method getCellSymbols with test

feature-chess
Nick Stolbov 2 years ago
parent
commit
0707f2d628
  1. 52
      src/main/java/Game/ChessObj/ChessBoard.java
  2. 15
      src/test/java/Game/ChessObj/ChessBoardTest.java

52
src/main/java/Game/ChessObj/ChessBoard.java

@ -1,5 +1,7 @@
package Game.ChessObj;
import java.util.ArrayList;
public class ChessBoard {
private ChessFigure[][] board;
@ -24,6 +26,56 @@ public class ChessBoard {
}
}
/*
a b c d e f g h
1 |T| |Z| |I| |Q| |K| |I| |Z| |T|
2 |o| |o| |o| |o| |o| |o| |o| |o|
3
4
5
6
7 o o o o o o o o
8 T Z I Q K I Z T
*/
public ArrayList<String> getOutputBoard() {
ArrayList<String> outputBoard = new ArrayList<>();
String[][] cellSymbol = getCellSymbols();
outputBoard.add(" a b c d e f g h");
outputBoard.add(" ┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐");
for (int y = 0; y < board.length; y++) {
String line = "";
line += " " + (y + 1) + " │ ";
for (int x = 0; x < board[0].length; x++) {
line += (cellSymbol[y][x] + " │ ");
}
outputBoard.add(line);
if (y < 7)
outputBoard.add(" ├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤");
}
outputBoard.add(" └─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘");
return outputBoard;
}
public String[][] getCellSymbols() {
String[][] cellSymbol = new String[8][8];
for (int y = 0; y < board.length; y++) {
for (int x = 0; x < board[0].length; x++) {
cellSymbol[y][x] = (board[y][x] == null)?" ": board[y][x].getSymbol();
}
}
return cellSymbol;
}
public ChessFigure[][] getBoard() {
return this.board;
}

15
src/test/java/Game/ChessObj/ChessBoardTest.java

@ -51,4 +51,19 @@ class ChessBoardTest {
}
}
}
@Test
void getCellSymbols() {
String[][] expectedArray = {
{"|T|","|Z|","|I|","|Q|","|K|","|I|","|Z|","|T|"},
{"|o|","|o|","|o|","|o|","|o|","|o|","|o|","|o|"},
{" "," "," "," "," "," "," "," "},
{" "," "," "," "," "," "," "," "},
{" "," "," "," "," "," "," "," "},
{" "," "," "," "," "," "," "," "},
{" o "," o "," o "," o "," o "," o "," o "," o "},
{" T "," Z "," I "," Q "," K "," I "," Z "," T "}
};
assertArrayEquals(expectedArray, chessBoard.getCellSymbols());
}
}
Loading…
Cancel
Save