|
@@ -5,23 +5,40 @@ package rocks.zipcode.io.quiz3.arrays;
|
5
|
5
|
*/
|
6
|
6
|
public class TicTacToe {
|
7
|
7
|
|
|
8
|
+ private String[][] board;
|
|
9
|
+
|
8
|
10
|
public TicTacToe(String[][] board) {
|
|
11
|
+ this.board=board;
|
9
|
12
|
}
|
10
|
13
|
|
11
|
14
|
public String[] getRow(Integer value) {
|
12
|
|
- return null;
|
|
15
|
+ String[] result = new String[3];
|
|
16
|
+ result[0]= board[value][0];
|
|
17
|
+ result[1]= board[value][1];
|
|
18
|
+ result[2]= board[value][2];
|
|
19
|
+ return result;
|
13
|
20
|
}
|
14
|
21
|
|
15
|
22
|
public String[] getColumn(Integer value) {
|
16
|
|
- return null;
|
|
23
|
+ String[] result = new String[3];
|
|
24
|
+ result[0]= board[0][value];
|
|
25
|
+ result[1]= board[1][value];
|
|
26
|
+ result[2]= board[2][value];
|
|
27
|
+ return result;
|
17
|
28
|
}
|
18
|
29
|
|
19
|
30
|
public Boolean isRowHomogenous(Integer rowIndex) {
|
20
|
|
- return null;
|
|
31
|
+ String[] row = getRow(rowIndex);
|
|
32
|
+ if(row[0].equals(row[1]) && row[1].equals(row[2]))
|
|
33
|
+ return true;
|
|
34
|
+ return false;
|
21
|
35
|
}
|
22
|
36
|
|
23
|
37
|
public Boolean isColumnHomogeneous(Integer columnIndex) {
|
24
|
|
- return null;
|
|
38
|
+ String[] column = getColumn(columnIndex);
|
|
39
|
+ if(column[0].equals(column[1]) && column[1].equals(column[2]))
|
|
40
|
+ return true;
|
|
41
|
+ return false;
|
25
|
42
|
}
|
26
|
43
|
|
27
|
44
|
public String getWinner() {
|