You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.1 KiB
82 lines
2.1 KiB
package Game.TicTacToe;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
public class Board {
|
|
|
|
enum State {
|
|
CIRCLE,
|
|
CROSS,
|
|
EMPTY
|
|
}
|
|
private State[] states;
|
|
|
|
|
|
public Board() {
|
|
states = new State[9];
|
|
for (int i = 0; i < states.length; i++) {
|
|
states[i] = State.EMPTY;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static char getStatedChar(State state) {
|
|
switch (state) {
|
|
case CIRCLE:
|
|
return 'O';
|
|
case CROSS:
|
|
return 'X';
|
|
case EMPTY:
|
|
return ' ';
|
|
default:
|
|
return '-';
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
1 ║2 ║3
|
|
o ║ x ║ o
|
|
═════╬═════╬═════
|
|
4 ║5 ║6
|
|
o ║ x ║ o
|
|
═════╬═════╬═════
|
|
7 ║8 ║9
|
|
o ║ x ║ o
|
|
*/
|
|
public ArrayList<String> getOutputBoard() {
|
|
ArrayList<String> outputBoard = new ArrayList<>();
|
|
outputBoard.add("1 ║2 ║3");
|
|
outputBoard.add(" " + getStatedChar(states[0]) + " ║ " + getStatedChar(states[1]) + " ║ " + getStatedChar(states[2]) +" ");
|
|
outputBoard.add("═════╬═════╬═════");
|
|
|
|
outputBoard.add("4 ║5 ║6");
|
|
outputBoard.add(" " + getStatedChar(states[3]) + " ║ " + getStatedChar(states[4]) + " ║ " + getStatedChar(states[5]) +" ");
|
|
outputBoard.add("═════╬═════╬═════");
|
|
|
|
outputBoard.add("7 ║8 ║9");
|
|
outputBoard.add(" " + getStatedChar(states[6]) + " ║ " + getStatedChar(states[7]) + " ║ " + getStatedChar(states[8]) +" ");
|
|
|
|
return outputBoard;
|
|
}
|
|
|
|
public State[] getStates() {
|
|
return this.states;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (!(o instanceof Board)) {
|
|
return false;
|
|
}
|
|
Board x = (Board)o;
|
|
for (int i = 0; i < x.getStates().length; i++) {
|
|
if (this.getStates()[i] != x.getStates()[i]) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|