From 60ec15241bec0e3b035ab75c2d372f177c0571a8 Mon Sep 17 00:00:00 2001 From: Malte Schellhardt Date: Sun, 30 Jan 2022 13:59:45 +0100 Subject: [PATCH] tictactoe: refactored board management and added constructor to handle different playfield sizes --- src/main/java/de/tims/tictactoe/GameLogic.java | 6 +++++- src/test/java/de/tims/tictactoe/GameLogicTest.java | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/tims/tictactoe/GameLogic.java b/src/main/java/de/tims/tictactoe/GameLogic.java index 07e2998..a449fdb 100644 --- a/src/main/java/de/tims/tictactoe/GameLogic.java +++ b/src/main/java/de/tims/tictactoe/GameLogic.java @@ -2,7 +2,11 @@ package de.tims.tictactoe; 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() { return this.board; diff --git a/src/test/java/de/tims/tictactoe/GameLogicTest.java b/src/test/java/de/tims/tictactoe/GameLogicTest.java index ac43308..d6d7176 100644 --- a/src/test/java/de/tims/tictactoe/GameLogicTest.java +++ b/src/test/java/de/tims/tictactoe/GameLogicTest.java @@ -8,7 +8,8 @@ import org.junit.jupiter.api.Test; class GameLogicTest { - private GameLogic game = new GameLogic(); + private int size = 3; + private GameLogic game = new GameLogic(size); @BeforeAll static void setUpBeforeClass() throws Exception { @@ -21,7 +22,7 @@ class GameLogicTest { @Test void createGameLogicTest() { GameLogic expectedResult = game; - GameLogic realResult = new GameLogic(); + GameLogic realResult = new GameLogic(size); assertEquals(expectedResult.getClass(), realResult.getClass()); }