-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBoard.java
More file actions
40 lines (32 loc) · 906 Bytes
/
Copy pathBoard.java
File metadata and controls
40 lines (32 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.ArrayList;
public class Board implements Cloneable {
private Cell[] cells;
private int cellsTaken = 0;
public Cell[] getCells() {
return cells;
}
public Cell getCell(int pos) {
return cells[pos];
}
public Board() {
cells = new Cell[]{ new Cell(0), new Cell(1), new Cell(2), new Cell(3),
new Cell(4), new Cell(5), new Cell(6), new Cell(7), new Cell(8) };
}
//cloning
@Override
protected Object clone() throws CloneNotSupportedException {
Board copy = (Board)super.clone();
Cell[] cellsCopy = new Cell[9];
for (int i = 0; i < 9; i++) {
cellsCopy[i] = new Cell(cells[i]);
}
copy.cells = cellsCopy;
return copy;
}
public boolean isFull() {
return cellsTaken == 9;
}
public void takeCell() {
cellsTaken++;
}
}