diff --git a/src/main/java/Game/Chess.java b/src/main/java/Game/Chess.java index 26a0c51..76922f1 100644 --- a/src/main/java/Game/Chess.java +++ b/src/main/java/Game/Chess.java @@ -1,6 +1,9 @@ package Game; import Game.ChessObj.ChessBoard; +import Game.ChessObj.ChessFigure; + +import java.util.ArrayList; public class Chess extends Game { @@ -50,4 +53,28 @@ public class Chess extends Game { else return temp; } + + public ArrayList getSidebarFigures(ArrayList chessFigureArrayList, int maxPerLine) { + ArrayList result = new ArrayList<>(); + String line = ""; + int counter = 0; + + for(int i = 0; i < chessFigureArrayList.size(); i++){ + if(i == chessFigureArrayList.size() - 1) { + line += chessFigureArrayList.get(i).getSymbol() + ""; + result.add(line); + return result; + } + line += chessFigureArrayList.get(i).getSymbol() + ","; + counter++; + if(counter >= maxPerLine) { + result.add(line); + line = ""; + counter = 0; + } + } + + return result; + } + } diff --git a/src/test/java/Game/ChessTest.java b/src/test/java/Game/ChessTest.java index 8dc691c..bf6ff9b 100644 --- a/src/test/java/Game/ChessTest.java +++ b/src/test/java/Game/ChessTest.java @@ -1,11 +1,13 @@ package Game; +import Game.ChessObj.ChessFigure; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertNull; +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.*; class ChessTest { @@ -40,4 +42,34 @@ class ChessTest { assertArrayEquals((chess.convertInput("3G")), test3); assertArrayEquals((chess.convertInput("G3")), test3); } + + @Test + void getSidebarFigures() { + ArrayList array1 = new ArrayList<>(); + ArrayList array2 = new ArrayList<>(); + ArrayList array3 = new ArrayList<>(); + ArrayList expectedArray2 = new ArrayList<>(); + ArrayList expectedArray3 = new ArrayList<>(); + + array2.add(new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.WHITE)); + array2.add(new ChessFigure(ChessFigure.Type.BISHOP, ChessFigure.Team.WHITE)); + array2.add(new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.WHITE)); + array2.add(new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.WHITE)); + array2.add(new ChessFigure(ChessFigure.Type.CASTLE, ChessFigure.Team.WHITE)); + array2.add(new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.WHITE)); + + expectedArray2.add(" o , I , o , o , T ,"); + expectedArray2.add(" o "); + + array3.add(new ChessFigure(ChessFigure.Type.QUEEN, ChessFigure.Team.BLACK)); + array3.add(new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.BLACK)); + array3.add(new ChessFigure(ChessFigure.Type.KING, ChessFigure.Team.BLACK)); + array3.add(new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.BLACK)); + + expectedArray3.add("|Q|,|o|,|K|,|o|"); + + assertEquals(0, chess.getSidebarFigures(array1, 5).size()); + assertEquals(expectedArray2, chess.getSidebarFigures(array2, 5)); + assertEquals(expectedArray3, chess.getSidebarFigures(array3, 5)); + } } \ No newline at end of file