Browse Source

Game TTT added Board creation

feature-game
Dion Aliu 3 years ago
parent
commit
03628a0e1f
  1. 22
      src/main/java/Game/Tictactoe.java
  2. 8
      src/test/java/Game/TictactoeTest.java

22
src/main/java/Game/Tictactoe.java

@ -3,6 +3,8 @@ package Game;
import java.util.ArrayList; import java.util.ArrayList;
public class Tictactoe implements Game { public class Tictactoe implements Game {
enum State { enum State {
CIRCLE, CIRCLE,
CROSS, CROSS,
@ -10,6 +12,15 @@ public class Tictactoe implements Game {
} }
private ArrayList<String> outputBuffer = new ArrayList<String>(); private ArrayList<String> outputBuffer = new ArrayList<String>();
private String input; private String input;
private State[] currentBoard;
public Tictactoe() {
init();
}
private void init() {
currentBoard = newBoard();
}
@Override @Override
public void print() { 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<String> outputBuffer){ void setOutputBuffer(ArrayList<String> outputBuffer){
this.outputBuffer = outputBuffer; this.outputBuffer = outputBuffer;
} }
public State[] getCurrentBoard() {
return currentBoard;
}
} }

8
src/test/java/Game/TictactoeTest.java

@ -47,4 +47,12 @@ class TictactoeTest {
assertEquals(ttt.getStatedChar(Tictactoe.State.CROSS), 'X'); assertEquals(ttt.getStatedChar(Tictactoe.State.CROSS), 'X');
assertEquals(ttt.getStatedChar(Tictactoe.State.EMPTY), ' '); 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);
}
}
} }
Loading…
Cancel
Save