-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrintMap.java
68 lines (56 loc) · 1.79 KB
/
PrintMap.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
public class PrintMap {
ArrayList<ArrayList<String>> mapGrid;
int height;
int width;
public PrintMap(InputParser input) {
mapGrid = new ArrayList<ArrayList<String>>(input.mapHeight);
height = input.mapHeight;
width = input.mapWidth;
String space;
for (int y = 0; y < input.mapHeight; y++) {
mapGrid.add(new ArrayList<String>(input.mapWidth));
for (int x = 0; x < input.mapWidth; x++) {
space = "<>";
for (Mine m : input.mines) {
if (m.x == y && m.y == x)
space = m.tag.toUpperCase();
}
if (space.equals("<>")) {
for (Factory f : input.factories) {
if (f.x == x && f.y == y) {
space = f.tag;
}
}
}
if (space.length() != 2) {
space = space + "!";
}
mapGrid.get(y).add(space);
}
}
}
public void print() {
try {
PrintWriter pr = new PrintWriter(new FileWriter("map2"));
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
pr.print(mapGrid.get(y).get(x));
}
pr.println();
}
pr.close();
}
catch (Exception e) {
}
}
public static void main(String[] args) {
String fileName = "maps/map_2.input";
InputParser input = new InputParser(fileName);
input.read();
PrintMap map = new PrintMap(input);
map.print();
}
}