-
Notifications
You must be signed in to change notification settings - Fork 0
/
MazePrinter.java
67 lines (56 loc) · 1.52 KB
/
MazePrinter.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
public class MazePrinter {
// static class
private MazePrinter() {
}
enum PrinterBlocks {
WALL("##"), PATH("PP"), AIR(" "), DESTROY("XX");
private final String block;
PrinterBlocks(String s) {
block = s;
}
String val() {
return block;
}
}
static void printMaze(Maze maze) {
for (int i = 0; i < maze.getRows(); ++i) {
System.out.print(PrinterBlocks.WALL.val());
for (int j = 0; j < maze.getColumns(); ++j) {
Room room = maze.getRoom(i, j);
if (room.hasNorthWall()) {
System.out.print(PrinterBlocks.WALL.val());
} else {
if (i > 0 && maze.getRoom(i - 1, j).onPath && room.onPath) {
System.out.print(PrinterBlocks.PATH.val());
} else {
System.out.print(PrinterBlocks.AIR.val());
}
}
System.out.print(PrinterBlocks.WALL.val());
}
System.out.print("\n");
for (int j = 0; j < maze.getColumns(); ++j) {
Room room = maze.getRoom(i, j);
if (room.hasWestWall()) {
System.out.print(PrinterBlocks.WALL.val());
} else {
if (j > 0 && maze.getRoom(i, j - 1).onPath && room.onPath) {
System.out.print(PrinterBlocks.PATH.val());
} else {
System.out.print(PrinterBlocks.AIR.val());
}
}
if (room.onPath) {
System.out.print(PrinterBlocks.PATH.val());
} else {
System.out.print(PrinterBlocks.AIR.val());
}
}
System.out.println(PrinterBlocks.WALL.val());
}
for (int j = 0; j < maze.getColumns() * 2 + 1; ++j) {
System.out.print(PrinterBlocks.WALL.val());
}
System.out.print("\n");
}
}