From 5c7908c23fd0d3a7e70f264a5181553ead7ab226 Mon Sep 17 00:00:00 2001 From: Malte Schellhardt Date: Wed, 9 Feb 2022 17:27:48 +0100 Subject: [PATCH] tictactoe: added test case to check if player 2 has won in row 0 --- src/main/java/de/tims/tictactoe/GameLogic.java | 9 +++++++++ src/test/java/de/tims/tictactoe/GameLogicTest.java | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/tims/tictactoe/GameLogic.java b/src/main/java/de/tims/tictactoe/GameLogic.java index 49582bc..6fc6f9f 100644 --- a/src/main/java/de/tims/tictactoe/GameLogic.java +++ b/src/main/java/de/tims/tictactoe/GameLogic.java @@ -53,6 +53,15 @@ public class GameLogic { } if(countFields == this.board.length) finished = true; + // check rows + for (int i = 0; i < this.board[0].length; i++) { + for (int j = 0; j < this.board.length; j++) { + if(board[i][j] == player) countFields++; + break; + } + } + if(countFields == this.board.length) 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 266d2bc..223fd9c 100644 --- a/src/test/java/de/tims/tictactoe/GameLogicTest.java +++ b/src/test/java/de/tims/tictactoe/GameLogicTest.java @@ -149,7 +149,11 @@ class GameLogicTest { Arguments.of("check win in row 0 for player 1", 'x', true, new char[][] {{'x', 'x', 'x'}, {'o', '-', '-'}, - {'-', '-', 'o'}}) + {'-', '-', 'o'}}), + Arguments.of("check win in row 0 for player 2", 'x', true, new char[][] + {{'o', 'o', 'o'}, + {'x', 'o', '-'}, + {'-', '-', 'x'}}) ); }