diff --git a/src/main/java/de/tims/tictactoe/GameLogic.java b/src/main/java/de/tims/tictactoe/GameLogic.java index 6fed5b6..ffaa984 100644 --- a/src/main/java/de/tims/tictactoe/GameLogic.java +++ b/src/main/java/de/tims/tictactoe/GameLogic.java @@ -64,6 +64,13 @@ public class GameLogic { countFields = 0; } + // check diagonal left + for (int i = this.board.length - 1, j = this.board.length - 1; i >= 0 ; i--, j--) { + if (board[i][j] == player) countFields++; + } + if(countFields == this.board.length) return finished = true; + + return finished; } diff --git a/src/test/java/de/tims/tictactoe/GameLogicTest.java b/src/test/java/de/tims/tictactoe/GameLogicTest.java index 30ab928..216e02c 100644 --- a/src/test/java/de/tims/tictactoe/GameLogicTest.java +++ b/src/test/java/de/tims/tictactoe/GameLogicTest.java @@ -196,13 +196,17 @@ class GameLogicTest { {'-', '-', '-'}}), Arguments.of("check a draw for player 2", 'o', false, new char[][] {{'o', 'o', 'x'}, - {'o', 'o', 'x'}, + {'o', 'x', 'x'}, {'x', 'x', 'o'}}), Arguments.of("check a draw for player 1", 'x', false, new char[][] {{'o', 'o', 'x'}, {'o', 'o', 'x'}, - {'x', 'x', 'o'}}) - ); + {'x', 'x', 'o'}}), + Arguments.of("check diagonal left win for player 1", 'x', true, new char[][] + {{'x', 'o', 'x'}, + {'x', 'x', 'o'}, + {'o', 'o', 'x'}}) + ); } }