- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstract_Factory.cpp
More file actions
Latest commit
82 lines (66 loc) · 1.26 KB
/
Copy pathAbstract_Factory.cpp
File metadata and controls
82 lines (66 loc) · 1.26 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
74
75
76
77
//side of the room
enum Direction { North, South, East, West };
//Mapsite is the common abstract class for all the components of maze
classMapSite
{
public:
virtualvoidEnter() = 0;
};
classRoom : publicMapSite {
public:
Room(int roomNo){};
MapSite* GetSide(Direction) const;
voidSetSide(Direction, MapSite*);
virtualvoidEnter(){};
private:
MapSite* _sides[4];
int _roomNumber;
};
classWall : publicMapSite {
public:
Wall(){};
virtualvoidEnter(){};
};
classDoor : publicMapSite {
public:
Door(Room* = 0, Room* = 0){};
Room* OtherSideFrom(Room*);
virtualvoidEnter(){};
private:
Room* _room1;
Room* _room2;
bool _isOpen;
};
classMaze {
public:
Maze(){};
voidAddRoom(Room*);
voidAddRoo1(){};
Room* RoomNo(int) const;
private:
};
classMazeFactory : publicMaze{
public:
MazeFactory(){};
virtual Maze* MakeMaze() const{
returnnewMaze();
}
virtual Wall* MakeWall() const{
returnnewWall();
}
virtual Room* MakeRoom(int n) const{
returnnewRoom(n);
}
virtual Door* MakeDoor(Room* r1, Room* r2) const{
returnnewDoor(r1, r1);
}
};
intmain()
{
MazeFactory* p = newMazeFactory();
Maze x;
p->MakeMaze();
p = (MazeFactory*)p->MakeMaze();
p->AddRoo1();
//p = (MazeFactory*)&x;
}