Browse Source

Game Interface TTT getStatedChar Method

feature-game
Dion Aliu 3 years ago
parent
commit
f58cbf0a2e
  1. 20
      src/main/java/Game/Tictactoe.java
  2. 10
      src/test/java/Game/TictactoeTest.java

20
src/main/java/Game/Tictactoe.java

@ -3,7 +3,13 @@ package Game;
import java.util.ArrayList; import java.util.ArrayList;
public class Tictactoe implements Game { public class Tictactoe implements Game {
enum State {
CIRCLE,
CROSS,
EMPTY
}
private ArrayList<String> outputBuffer = new ArrayList<String>(); private ArrayList<String> outputBuffer = new ArrayList<String>();
private String input;
@Override @Override
public void print() { public void print() {
@ -12,6 +18,20 @@ public class Tictactoe implements Game {
} }
} }
public char getStatedChar(State state) {
switch (state) {
case CIRCLE:
return 'O';
case CROSS:
return 'X';
case EMPTY:
return ' ';
default:
return '-';
}
}
void setOutputBuffer(ArrayList<String> outputBuffer){ void setOutputBuffer(ArrayList<String> outputBuffer){
this.outputBuffer = outputBuffer; this.outputBuffer = outputBuffer;
} }

10
src/test/java/Game/TictactoeTest.java

@ -1,7 +1,5 @@
package Game; package Game;
import org.junit.Rule;
import org.junit.contrib.java.lang.system.SystemOutRule;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -41,4 +39,12 @@ class TictactoeTest {
ttt.print(); ttt.print();
assertEquals("Hello\nWorld\n!!!\n", outContent.toString().replaceAll("\r", "")); assertEquals("Hello\nWorld\n!!!\n", outContent.toString().replaceAll("\r", ""));
} }
@Test
void getStatedChar() {
assertEquals(ttt.getStatedChar(Tictactoe.State.CIRCLE), 'O');
assertEquals(ttt.getStatedChar(Tictactoe.State.CROSS), 'X');
assertEquals(ttt.getStatedChar(Tictactoe.State.EMPTY), ' ');
}
} }
Loading…
Cancel
Save