From f58cbf0a2efcaedab5ae977a6489a18f128f720e Mon Sep 17 00:00:00 2001 From: Dion Aliu Date: Wed, 19 Jan 2022 11:18:53 +0100 Subject: [PATCH] Game Interface TTT getStatedChar Method --- src/main/java/Game/Tictactoe.java | 22 +++++++++++++++++++++- src/test/java/Game/TictactoeTest.java | 10 ++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/Game/Tictactoe.java b/src/main/java/Game/Tictactoe.java index 87da6c4..5be7517 100644 --- a/src/main/java/Game/Tictactoe.java +++ b/src/main/java/Game/Tictactoe.java @@ -3,15 +3,35 @@ package Game; import java.util.ArrayList; public class Tictactoe implements Game { + enum State { + CIRCLE, + CROSS, + EMPTY + } private ArrayList outputBuffer = new ArrayList(); + private String input; @Override public void print() { for (int i = 0; i < outputBuffer.size(); i++) { - System.out.println(outputBuffer.get(i)); + System.out.println(outputBuffer.get(i)); } } + public char getStatedChar(State state) { + switch (state) { + case CIRCLE: + return 'O'; + case CROSS: + return 'X'; + case EMPTY: + return ' '; + default: + return '-'; + } + } + + void setOutputBuffer(ArrayList outputBuffer){ this.outputBuffer = outputBuffer; } diff --git a/src/test/java/Game/TictactoeTest.java b/src/test/java/Game/TictactoeTest.java index 55d7874..39a6f3e 100644 --- a/src/test/java/Game/TictactoeTest.java +++ b/src/test/java/Game/TictactoeTest.java @@ -1,7 +1,5 @@ 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.BeforeEach; import org.junit.jupiter.api.Test; @@ -41,4 +39,12 @@ class TictactoeTest { ttt.print(); 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), ' '); + } } \ No newline at end of file