-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.java
More file actions
91 lines (71 loc) · 2.71 KB
/
Board.java
File metadata and controls
91 lines (71 loc) · 2.71 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.util.Arrays;
import java.util.Random;
//this class is to initiate the board
public class Board {
public static void main(String[] args) {
Board b = new Board();
b.display();
}
protected int size;
private Cell[][] status;
public Board(){
// construct a new board
this.size = 8;
this.status = generate();
}
public Cell[][] generate(){
Cell[][] sample = new Cell[this.size][this.size];
CellFactory cellFactory = new CellFactory();
Random random = new Random();
for (int i = 0; i < this.size; i++){
for (int j = 0; j < this.size; j++){
if ( i == 2 || i== 5){
sample[i][j] = cellFactory.create(5);
}else{
if (j == 0 || j == 7){
sample[i][j] = cellFactory.create(6);
}else {
int randomNumber = random.nextInt(4) + 1;
sample[i][j] = cellFactory.create(randomNumber);
}
}
}
}
return sample;
}
public int getSize() {
return size;
}
public Cell[][] getStatus(){
return this.status;
}
public void display(){
for (int j = this.size - 1;j >=0;j--) {
for (int i = 0; i < this.size; i++) {
Cell currentCell = this.status[i][j];
char letter = currentCell.getLetter();
String line = " " + letter + " - " + letter + " - " + letter + " ";
System.out.print(line);
}
System.out.println();
for (int i = 0; i < this.size; i++) {
Cell currentCell = this.status[i][j];
char letter = currentCell.getLetter();
String info = currentCell.getCurrentInfo();
System.out.print(" | " + info + " | ");
}
System.out.println();
for (int i = 0; i < this.size; i++) {
Cell currentCell = this.status[i][j];
char letter = currentCell.getLetter();
String line = " " + letter + " - " + letter + " - " + letter + " ";
System.out.print(line);
}
System.out.println();
for (int i = 0; i < this.size; i++) {
System.out.print(" ");
}
System.out.println();
}
}
}