diff --git a/src/main/java/Game/ChessObj/ChessBoard.java b/src/main/java/Game/ChessObj/ChessBoard.java index 0099da5..8b32b3c 100644 --- a/src/main/java/Game/ChessObj/ChessBoard.java +++ b/src/main/java/Game/ChessObj/ChessBoard.java @@ -70,12 +70,18 @@ public class ChessBoard { 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(); + cellSymbol[y][x] = (board[y][x] == null) ? " " : board[y][x].getSymbol(); } } return cellSymbol; } + public boolean isCellInBoard(int x, int y){ + if(x >= 0 && x < board[0].length && y >= 0 && y < board.length) + return true; + return false; + } + public ChessFigure[][] getBoard() { return this.board; } diff --git a/src/test/java/Game/ChessObj/ChessBoardTest.java b/src/test/java/Game/ChessObj/ChessBoardTest.java index d39bb27..0053e9f 100644 --- a/src/test/java/Game/ChessObj/ChessBoardTest.java +++ b/src/test/java/Game/ChessObj/ChessBoardTest.java @@ -66,4 +66,15 @@ class ChessBoardTest { }; assertArrayEquals(expectedArray, chessBoard.getCellSymbols()); } + + @Test + void isCellInBoard() { + assertTrue(chessBoard.isCellInBoard(0, 0)); + assertTrue(chessBoard.isCellInBoard(7, 7)); + assertTrue(chessBoard.isCellInBoard(2, 1)); + assertTrue(chessBoard.isCellInBoard(5, 7)); + assertFalse(chessBoard.isCellInBoard(-1, 0)); + assertFalse(chessBoard.isCellInBoard(4, 8)); + assertFalse(chessBoard.isCellInBoard(10, 20)); + } } \ No newline at end of file