-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMap.java
50 lines (44 loc) · 1.47 KB
/
Map.java
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
import java.util.*;
public class Map {
int n = 8;
private List<Cell> cellList = new ArrayList();
// according to the data provided, initialize a map;
public void initialize(){
int in = (int)(n * n * 0.2);
int m = (int)(n * n * 0.3);
int c = 64 - in - m;
CellFactory cellFactory = new CellFactory();
for(int j = 0; j < in; j++){
Cell cell = cellFactory.create_Cell("Inaccessible");
cellList.add(cell);
}
for(int j = 0; j < m; j++){
Cell cell = cellFactory.create_Cell("Market");
cellList.add(cell);
}
for(int j = 0; j < c; j++){
Cell cell = cellFactory.create_Cell("Common");
cellList.add(cell);
}
Collections.shuffle(cellList);
MarketCell mc = new MarketCell();
cellList.set(0, mc);
}
// return the cell which the hero party enters;
public Cell get_entered_cell(int[] new_location){
int m = new_location[0];
int n = new_location[1];
int index = (m - 1) * 8 + n - 1;
return cellList.get(index);
}
// print map on the terminal;
public void show_map(){
System.out.println("----------------------------------------");
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cellList.get(i * 8 + j).show();
}
System.out.println("\n----------------------------------------");
}
}
}