2
char[][] field; int size = 9; int countToWin = 5;
5
this.field = new char[size][size];
6
for (int row = 0; row < size; row++) {
7
for (int col = 0; col < size; col++) {
11
System.out.println("Field initialized");
16
System.out.print(" ");
17
for (int i = 1; i <= size; i++) {
18
System.out.print(i + " ");
21
for (int row = 0; row < size; row++) {
22
int rowNumber = row + 1;
23
System.out.print(rowNumber + " ");
24
for (int col = 0; col < size; col++) {
25
System.out.print("[" + this.field[row][col] + "]");
31
boolean isPlaceFree(int rowIndex, int colIndex) {
32
if (rowIndex<0 || rowIndex>=size || colIndex<0 || colIndex>=size) {
34
} else if (this.field[rowIndex][colIndex] == ' ') {
41
void setValue(int rowIndex, int colIndex, char value) {
42
this.field[rowIndex][colIndex] = value;
45
boolean isGameOver(char player) {
46
for (int row=0; row < this.size; row++) {
47
for (int col=0; col < this.size; col++) {
48
if (checkRightDirection(row, col, player)) {
50
} else if (checkDownDirection(row, col, player)) {
52
} else if (checkRightDiagonal(row, col, player)) {
54
} else if (checkLeftDiagonal(row, col, player)) {
61
boolean checkRightDirection(int row, int col, char player) {
62
if (col > this.size - this.countToWin) {
65
for (int i = col; i < col + this.countToWin; i++) {
66
if (this.field[row][i] != player) {
72
boolean checkDownDirection(int row, int col, char player) {
73
if (row > this.size - this.countToWin) {
76
for (int i = row; i < row + this.countToWin; i++) {
77
if (this.field[i][col] != player) {
83
boolean checkRightDiagonal(int row, int col, char player) {
84
if (row > this.size - this.countToWin) {
87
if (col > this.size - this.countToWin) {
90
for (int sdvig = 0; sdvig < this.countToWin; sdvig++) {
91
int rowToCheck = row + sdvig;
92
int colToCheck = col + sdvig;
93
if (this.field[rowToCheck][colToCheck] != player) {
99
boolean checkLeftDiagonal(int row, int col, char player) {
100
if (row > this.size - this.countToWin) {
103
if (col < this.countToWin - 1) {
106
for (int sdvig = 0; sdvig < this.countToWin; sdvig++) {
107
int rowToCheck = row + sdvig; int colToCheck = col - sdvig;
108
if (this.field[rowToCheck][colToCheck] != player) {