From 27c4b6122b1706cd7e72e05da17dc47a2a1fc02b Mon Sep 17 00:00:00 2001 From: Steffen Helmke Date: Mon, 10 Jan 2022 19:54:17 +0100 Subject: [PATCH] 4gewinnt: change to player 2 after player 1 played added --- src/main/java/de/tims/viergewinnt/ai/Logic.java | 5 ++++- src/test/java/de/tims/viergewinnt/ai/LogicTest.java | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/tims/viergewinnt/ai/Logic.java b/src/main/java/de/tims/viergewinnt/ai/Logic.java index 794d610..1aef7f6 100644 --- a/src/main/java/de/tims/viergewinnt/ai/Logic.java +++ b/src/main/java/de/tims/viergewinnt/ai/Logic.java @@ -17,8 +17,9 @@ public class Logic { int currentPlayer; public int playChip(int[][] playfield, int column, int player) { - + //add board update testForWin(playfield, player); + currentPlayer = 2; return 0; } @@ -45,6 +46,8 @@ public class Logic { for(int i = 0; i < gamefield.length; i++) { gamefield[i] = new JLabel(); gamefield[i].setBorder(BorderFactory.createLineBorder(Color.gray)); + gamefield[i].setOpaque(true); + gamefield[i].setBackground(Color.white); playfieldPanel.add(gamefield[i]); } diff --git a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java index 731b925..71cd919 100644 --- a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java +++ b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java @@ -39,6 +39,19 @@ class LogicTest { assertEquals(expectedResult, realResult); } + @Test + void changePlayerTo2Test() { + int[][] playfield = new int[6][6]; + int column = 0; + int player = 1; + int expectedResult = 2; + + testObj.playChip(playfield, column, player); + int realResult = testObj.currentPlayer; + + assertEquals(expectedResult, realResult); + } + private static Stream playfieldResults() { int[][] playfield1 = {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0},