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.
43 lines
815 B
43 lines
815 B
package de.tims.tictactoe;
|
|
|
|
import java.util.Arrays;
|
|
|
|
public class GameLogic {
|
|
|
|
private char[][] board;
|
|
private final char emptyField = '-';
|
|
|
|
public GameLogic(int size) {
|
|
if (size < 3) {
|
|
size = 3;
|
|
}
|
|
this.board = new char[size][size];
|
|
|
|
for (int i = 0; i < this.board.length; i++) {
|
|
for (int j = 0; j < this.board[0].length; j++) {
|
|
this.setField(i, j, '-');
|
|
}
|
|
}
|
|
}
|
|
|
|
public GameLogic(char[][] board) {
|
|
this.board = board;
|
|
}
|
|
|
|
public char[][] getBoard() {
|
|
return this.board;
|
|
}
|
|
|
|
public int countFields() {
|
|
return this.board[0].length * this.board.length;
|
|
}
|
|
|
|
public void setField(int column, int row, char player) {
|
|
this.board[column][row] = player;
|
|
}
|
|
|
|
public boolean fieldIsEmpty(int column, int row) {
|
|
return (this.board[column][row] == emptyField) ? true : false;
|
|
}
|
|
|
|
}
|