-
Notifications
You must be signed in to change notification settings - Fork 513
Expand file tree
/
Copy pathBoard.java
More file actions
73 lines (64 loc) · 1.91 KB
/
Copy pathBoard.java
File metadata and controls
73 lines (64 loc) · 1.91 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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Board {
private final int rows;
private final int columns;
private final Map<Integer,Integer> snakeMap;
private final Map<Integer,Integer> laddersMap;
private final List<List<Integer>> values;
public Board(int rows, int columns) {
this.rows = rows;
this.columns = columns;
values = new ArrayList<>(rows);
for(int i=0;i< rows;i++){
List<Integer> row = new ArrayList<>(columns);
for(int j=0;j<columns;j++) {
row.add(0);
}
values.add(row);
}
setupValues();
snakeMap = new HashMap<>();
laddersMap = new HashMap<>();
}
public int getRows() {
return rows;
}
public int getColumns() {
return columns;
}
private void setupValues() {
int start= rows * columns;
for(int i=0;i<rows;i++) {
if(i%2==0) {
for (int j = 0; j < columns; j++) {
values.get(i).set(j, start--);
}
}
else {
for (int j = columns-1; j >=0; j--) {
values.get(i).set(j, start--);
}
}
}
}
public Map<Integer, Integer> getSnakeMap() {
return snakeMap;
}
public Map<Integer, Integer> getLaddersMap() {
return laddersMap;
}
public void display() {
System.out.println("\n-----------------------Board State--------------------\n");
for(int i=0;i<rows;i++) {
for(int j=0;j<columns;j++) {
System.out.print(values.get(i).get(j));
System.out.print(" ");
}
System.out.println();
}
System.out.println("\n-----------------------END------------------------------\n");
}
}