From 03628a0e1fedc084e1b055efe9c2eab5738e51d1 Mon Sep 17 00:00:00 2001 From: Dion Aliu Date: Wed, 19 Jan 2022 11:39:32 +0100 Subject: [PATCH] Game TTT added Board creation --- src/main/java/Game/Tictactoe.java | 22 ++++++++++++++++++++++ src/test/java/Game/TictactoeTest.java | 8 ++++++++ 2 files changed, 30 insertions(+) diff --git a/src/main/java/Game/Tictactoe.java b/src/main/java/Game/Tictactoe.java index 5be7517..0988a12 100644 --- a/src/main/java/Game/Tictactoe.java +++ b/src/main/java/Game/Tictactoe.java @@ -3,6 +3,8 @@ package Game; import java.util.ArrayList; public class Tictactoe implements Game { + + enum State { CIRCLE, CROSS, @@ -10,6 +12,15 @@ public class Tictactoe implements Game { } private ArrayList outputBuffer = new ArrayList(); private String input; + private State[] currentBoard; + + public Tictactoe() { + init(); + } + + private void init() { + currentBoard = newBoard(); + } @Override public void print() { @@ -31,8 +42,19 @@ public class Tictactoe implements Game { } } + private State[] newBoard() { + State[] board = new State[9]; + for (int i = 0; i < board.length; i++) { + board[i] = State.EMPTY; + } + return board; + } void setOutputBuffer(ArrayList outputBuffer){ this.outputBuffer = outputBuffer; } + + public State[] getCurrentBoard() { + return currentBoard; + } } diff --git a/src/test/java/Game/TictactoeTest.java b/src/test/java/Game/TictactoeTest.java index 39a6f3e..998accf 100644 --- a/src/test/java/Game/TictactoeTest.java +++ b/src/test/java/Game/TictactoeTest.java @@ -47,4 +47,12 @@ class TictactoeTest { assertEquals(ttt.getStatedChar(Tictactoe.State.CROSS), 'X'); assertEquals(ttt.getStatedChar(Tictactoe.State.EMPTY), ' '); } + + @Test + void testForEmptyBoardOnInitialization() { + Tictactoe.State[] board = ttt.getCurrentBoard(); + for (int i = 0; i < board.length; i++) { + assertEquals(board[i], Tictactoe.State.EMPTY); + } + } } \ No newline at end of file