-
Notifications
You must be signed in to change notification settings - Fork 126
/
maze_game.h
49 lines (40 loc) · 1.05 KB
/
maze_game.h
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
// Copyright (c) 2016 Elements of Programming Interviews. All rights reserved.
#ifndef SOLUTIONS_MAZE_GAME_H_
#define SOLUTIONS_MAZE_GAME_H_
#include <iostream>
#include <vector>
using std::vector;
using std::cout;
class Room {
public:
virtual ~Room() = default;
virtual void Connect(const Room* that) = 0;
};
class MazeGame {
public:
void AddRoom(const Room* that) { rooms.push_back(that); }
private:
vector<const Room*> rooms;
};
// @include
class MazeGameCreator {
public:
virtual Room* MakeRoom() = 0;
// @exclude
virtual ~MazeGameCreator() = default;
// @include
// This factory method is a template method for creating MazeGame objects.
// MazeGameCreator's subclasses implement MakeRoom() as appropriate for
// the type of room being created.
MazeGame* FactoryMethod() {
MazeGame* mazeGame = new MazeGame();
Room* room1 = MakeRoom();
Room* room2 = MakeRoom();
room1->Connect(room2);
mazeGame->AddRoom(room1);
mazeGame->AddRoom(room2);
return mazeGame;
}
};
// @exclude
#endif // SOLUTIONS_MAZE_GAME_H_