|
@ -4,7 +4,6 @@ import java.util.ArrayList; |
|
|
|
|
|
|
|
|
public class Tictactoe extends Game { |
|
|
public class Tictactoe extends Game { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum State { |
|
|
enum State { |
|
|
CIRCLE, |
|
|
CIRCLE, |
|
|
CROSS, |
|
|
CROSS, |
|
@ -21,7 +20,10 @@ public class Tictactoe extends Game { |
|
|
currentBoard = newBoard(); |
|
|
currentBoard = newBoard(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void update(String string) { |
|
|
|
|
|
writeBoard(currentBoard); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public char getStatedChar(State state) { |
|
|
public char getStatedChar(State state) { |
|
|
switch (state) { |
|
|
switch (state) { |
|
@ -47,4 +49,27 @@ public class Tictactoe extends Game { |
|
|
public State[] getCurrentBoard() { |
|
|
public State[] getCurrentBoard() { |
|
|
return currentBoard; |
|
|
return currentBoard; |
|
|
} |
|
|
} |
|
|
|
|
|
/* |
|
|
|
|
|
1 ║2 ║3 |
|
|
|
|
|
o ║ x ║ o |
|
|
|
|
|
═════╬═════╬═════ |
|
|
|
|
|
4 ║5 ║6 |
|
|
|
|
|
o ║ x ║ o |
|
|
|
|
|
═════╬═════╬═════ |
|
|
|
|
|
7 ║8 ║9 |
|
|
|
|
|
o ║ x ║ o |
|
|
|
|
|
*/ |
|
|
|
|
|
private void writeBoard(State[] state) { |
|
|
|
|
|
this.outputBuffer.clear(); |
|
|
|
|
|
outputBuffer.add("1 ║2 ║3"); |
|
|
|
|
|
outputBuffer.add(" " + getStatedChar(state[0]) + " ║ " + getStatedChar(state[1]) + " ║ " + getStatedChar(state[2]) +" "); |
|
|
|
|
|
outputBuffer.add("═════╬═════╬═════"); |
|
|
|
|
|
|
|
|
|
|
|
outputBuffer.add("4 ║5 ║6"); |
|
|
|
|
|
outputBuffer.add(" " + getStatedChar(state[3]) + " ║ " + getStatedChar(state[4]) + " ║ " + getStatedChar(state[5]) +" "); |
|
|
|
|
|
outputBuffer.add("═════╬═════╬═════"); |
|
|
|
|
|
|
|
|
|
|
|
outputBuffer.add("7 ║8 ║9"); |
|
|
|
|
|
outputBuffer.add(" " + getStatedChar(state[6]) + " ║ " + getStatedChar(state[7]) + " ║ " + getStatedChar(state[8]) +" "); |
|
|
|
|
|
} |
|
|
} |
|
|
} |