-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameBoard.java
More file actions
73 lines (61 loc) · 1.52 KB
/
Copy pathGameBoard.java
File metadata and controls
73 lines (61 loc) · 1.52 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import com.sun.source.tree.BreakTree;
import java.util.Arrays;
/**
* basic board class
*/
public class GameBoard {
protected final int BOARD_SIZE = 8;
protected Cell[][] cells;
public GameBoard() {
cells = new Cell[BOARD_SIZE][BOARD_SIZE];
}
public GameBoard(int x, int y) {
cells = new Cell[x][y];
}
public void init() {
for (int i = 0; i < cells.length; i++) {
for (int j = 0; j < cells[i].length; j++) {
cells[i][j] = new Cell();
}
}
}
public Cell getCell(int i, int j) {
return cells[i][j];
}
public void setCell(int i, int j, Cell cell) {
cells[i][j] = cell;
}
public Cell[][] getCells() {
return cells;
}
public int getBoardRows() {
return cells.length;
}
public int getBoardCols() {
return cells[0].length;
}
public void setCells(Cell[][] cells) {
this.cells = cells;
}
@Override
public String toString() {
String str = "";
// draw the row lines
String row = "";
for (int i = 0; i < getBoardCols(); i++) {
row += "+---";
}
row += "+\n";
for (int j = 0; j < getBoardRows(); j++) {
str += row;
for (int k = 0; k < getBoardCols(); k++) {
str += "| ";
str += cells[j][k].toString();
str += " ";
}
str += "|\n";
}
str += row;
return str;
}
}