-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart3.java
123 lines (98 loc) · 3.33 KB
/
part3.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import java.util.HashMap;
import java.util.Map;
interface MazePrototypeFactory {
Maze makeMaze();
Room makeRoom(int roomNo);
Wall makeWall();
DoorWall makeDoorWall(Room r1, Room r2);
}
class OriginalMazePrototypeFactory implements MazePrototypeFactory {
@Override
public Maze makeMaze() {
return new Maze();
}
@Override
public Room makeRoom(int roomNo) {
return new Room(roomNo);
}
@Override
public Wall makeWall() {
return new Wall();
}
@Override
public DoorWall makeDoorWall(Room r1, Room r2) {
return new DoorWall(r1, r2);
}
}
class NewMazePrototypeFactory implements MazePrototypeFactory {
@Override
public Maze makeMaze() {
return new Maze();
}
@Override
public Room makeRoom(int roomNo) {
return new Room(roomNo);
}
@Override
public Wall makeWall() {
// New implementation of wall for the new game
return new ColorfulWall(); // for example
}
class ColorfulWall extends Wall {
}
class SecretDoorWall extends DoorWall {
public SecretDoorWall(Room r1, Room r2) {
super(r1, r2);
}
}
@Override
public DoorWall makeDoorWall(Room r1, Room r2) {
return new SecretDoorWall(r1, r2); // for example
}
}
public class part3 {
public static void main(String[] argv) {
createOriginalMaze();
createNewMaze();
}
private static void createOriginalMaze() {
MazePrototypeFactory factory = new OriginalMazePrototypeFactory();
Maze aMaze = factory.makeMaze();
Room r1 = factory.makeRoom(1);
Room r2 = factory.makeRoom(2);
DoorWall d = factory.makeDoorWall(r1, r2);
aMaze.addRoom(r1);
aMaze.addRoom(r2);
r1.setSide(Direction.NORTH, d);
r1.setSide(Direction.EAST, factory.makeWall());
r1.setSide(Direction.SOUTH, factory.makeWall());
r1.setSide(Direction.WEST, factory.makeWall());
r2.setSide(Direction.NORTH, factory.makeWall());
r2.setSide(Direction.EAST, factory.makeWall());
r2.setSide(Direction.SOUTH, d);
r2.setSide(Direction.WEST, factory.makeWall());
// Output information about the created maze
System.out.println("Original Maze Created:");
System.out.println(aMaze);
}
private static void createNewMaze() {
MazePrototypeFactory factory = new NewMazePrototypeFactory();
Maze aMaze = factory.makeMaze();
Room r1 = factory.makeRoom(1);
Room r2 = factory.makeRoom(2);
DoorWall d = factory.makeDoorWall(r1, r2);
aMaze.addRoom(r1);
aMaze.addRoom(r2);
r1.setSide(Direction.NORTH, d);
r1.setSide(Direction.EAST, factory.makeWall());
r1.setSide(Direction.SOUTH, factory.makeWall());
r1.setSide(Direction.WEST, factory.makeWall());
r2.setSide(Direction.NORTH, factory.makeWall());
r2.setSide(Direction.EAST, factory.makeWall());
r2.setSide(Direction.SOUTH, d);
r2.setSide(Direction.WEST, factory.makeWall());
// Output information about the created maze
System.out.println("New Maze Created:");
System.out.println(aMaze);
}
}