-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgamebuilder.h
More file actions
executable file
·78 lines (69 loc) · 2.41 KB
/
gamebuilder.h
File metadata and controls
executable file
·78 lines (69 loc) · 2.41 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
78
#pragma once
#include "stageonefactory.h"
#include "game.h"
class GameBuilder {
protected:
AbstractStageFactory* m_factory = nullptr;
public:
virtual ~GameBuilder() { delete m_factory; }
GameBuilder(AbstractStageFactory* factory) : m_factory(factory) {}
/**
* @brief addBall creates a ball to the current game being buil
* @param ballData - json object that is simply an element of the array of balls provided in the config
*/
virtual void addBall(QJsonObject& ballData) = 0;
/**
* @brief addTable creates a table to the current game being built
* @param tableData - json object that contains all properties of the table
*/
virtual void addTable(QJsonObject& tableData) = 0;
/**
* @brief getResult - retrieve the building
* @return
*/
virtual Game* getResult() = 0;
};
class StageOneBuilder : public GameBuilder {
std::vector<Ball*>* m_buildingBalls = nullptr;
Table* m_buildingTable = nullptr;
public:
~StageOneBuilder();
StageOneBuilder() : GameBuilder(new StageOneFactory()) {}
StageOneBuilder(AbstractStageFactory* factory) : GameBuilder(factory) {}
/**
* @brief addBall creates a ball to the current game being built
* @param ballData - json object that is simply an element of the array of balls provided in the config
*/
void addBall(QJsonObject &ballData) override;
/**
* @brief addTable creates a table to the current game being built
* @param tableData - json object that contains all properties of the table
*/
void addTable(QJsonObject& tableData) override;
/**
* @brief getResult - retrieve the building
* @return
*/
Game* getResult() override;
};
class StageTwoBuilder : public StageOneBuilder {
public:
StageTwoBuilder() : StageOneBuilder(new StageTwoFactory()) {}
};
class GameDirector {
GameBuilder* m_builder;
const QJsonObject* m_conf;
public:
~GameDirector() { delete m_builder; /* ): json object is owned by other */ }
GameDirector(QJsonObject* conf) : m_conf(conf) {}
/**
* @brief setBuilder - change which builder should be used for construction
* @param newBuilder - the new builder
*/
void setBuilder(GameBuilder* newBuilder) { m_builder = newBuilder; }
/**
* @brief createGame - retrieve the building that our owned builder created
* @return - the newly created game
*/
Game* createGame();
};