|
@ -5,7 +5,7 @@ import java.util.Arrays; |
|
|
public class GameLogic { |
|
|
public class GameLogic { |
|
|
|
|
|
|
|
|
private char[][] board; |
|
|
private char[][] board; |
|
|
private final char emptyField = '-'; |
|
|
|
|
|
|
|
|
private final char[] occupiedFields = { 'x', 'o' }; |
|
|
|
|
|
|
|
|
public GameLogic(int size) { |
|
|
public GameLogic(int size) { |
|
|
if (size < 3) { |
|
|
if (size < 3) { |
|
@ -33,11 +33,14 @@ public class GameLogic { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setField(int column, int row, char player) { |
|
|
public void setField(int column, int row, char player) { |
|
|
this.board[column][row] = player; |
|
|
|
|
|
|
|
|
if(fieldIsEmpty(column, row)) this.board[column][row] = player; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public boolean fieldIsEmpty(int column, int row) { |
|
|
public boolean fieldIsEmpty(int column, int row) { |
|
|
return (this.board[column][row] == emptyField) ? true : false; |
|
|
|
|
|
|
|
|
for (char field : this.occupiedFields) { |
|
|
|
|
|
if (this.board[column][row] == field) return false; |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |