diff --git a/src/main/java/de/tims/tictactoe/GameLogic.java b/src/main/java/de/tims/tictactoe/GameLogic.java index 1591cd1..0becf7a 100644 --- a/src/main/java/de/tims/tictactoe/GameLogic.java +++ b/src/main/java/de/tims/tictactoe/GameLogic.java @@ -1,12 +1,13 @@ package de.tims.tictactoe; import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; -import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JPanel; -public class GameLogic { +public class GameLogic implements ActionListener { private static final char PLAYER_1 = 'x'; private static final char PLAYER_2 = 'o'; @@ -110,9 +111,20 @@ public class GameLogic { for (int i = 0; i < this.fields.length; i++) { this.fields[i] = new JButton(); + this.fields[i].addActionListener(this); this.contentPanel.add(this.fields[i]); } return this.contentPanel; } + public JButton getGUIField(int number) { + // TODO Auto-generated method stub + return this.fields[number]; + } + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + } + } diff --git a/src/test/java/de/tims/tictactoe/GameLogicTest.java b/src/test/java/de/tims/tictactoe/GameLogicTest.java index 19ab25a..fddac3c 100644 --- a/src/test/java/de/tims/tictactoe/GameLogicTest.java +++ b/src/test/java/de/tims/tictactoe/GameLogicTest.java @@ -81,6 +81,18 @@ class GameLogicTest { assertEquals(expectedResult, realResult); } + @Test + void buttonStateTest() { + boolean expectedResult = true; + game.generateGUI(); + + JButton currentField = game.getGUIField(0); + ((JButton) currentField).doClick(); + boolean realResult = currentField.isEnabled(); + + assertEquals(expectedResult, realResult); + } + @ParameterizedTest(name = "[{index}] {0} -> {2} fields") @MethodSource("testCasesForCountPlayfields") void fieldCountTest(String testName, int size, int expectedResult) {