Browse Source

tictactoe: refactored board management and added constructor to handle different playfield sizes

tictactoe
Malte Schellhardt 3 years ago
committed by Lorenz Hohmann
parent
commit
60ec15241b
  1. 6
      src/main/java/de/tims/tictactoe/GameLogic.java
  2. 5
      src/test/java/de/tims/tictactoe/GameLogicTest.java

6
src/main/java/de/tims/tictactoe/GameLogic.java

@ -2,7 +2,11 @@ package de.tims.tictactoe;
public class GameLogic { public class GameLogic {
private int[][] board = new int[3][3];
private int[][] board;
public GameLogic(int size) {
this.board = new int[size][size];
}
public int[][] getBoard() { public int[][] getBoard() {
return this.board; return this.board;

5
src/test/java/de/tims/tictactoe/GameLogicTest.java

@ -8,7 +8,8 @@ import org.junit.jupiter.api.Test;
class GameLogicTest { class GameLogicTest {
private GameLogic game = new GameLogic();
private int size = 3;
private GameLogic game = new GameLogic(size);
@BeforeAll @BeforeAll
static void setUpBeforeClass() throws Exception { static void setUpBeforeClass() throws Exception {
@ -21,7 +22,7 @@ class GameLogicTest {
@Test @Test
void createGameLogicTest() { void createGameLogicTest() {
GameLogic expectedResult = game; GameLogic expectedResult = game;
GameLogic realResult = new GameLogic();
GameLogic realResult = new GameLogic(size);
assertEquals(expectedResult.getClass(), realResult.getClass()); assertEquals(expectedResult.getClass(), realResult.getClass());
} }

Loading…
Cancel
Save