Skip to content

Commit 268eb2c

Browse files
committed
Merge pull request #68 from Databean/GameController_refactor
Game controller refactor
2 parents a43e3d6 + 5d6b079 commit 268eb2c

File tree

5 files changed

+215
-75
lines changed

5 files changed

+215
-75
lines changed

include/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ConfigValue {
2727
operator std::string() const;
2828
operator Coordinate() const;
2929
operator ScreenCoordinate() const;
30+
operator std::pair<ScreenCoordinate, ScreenCoordinate>() const;
3031
};
3132

3233
/**

include/GameController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GameController {
2525
GameBoard& model;
2626
GameView& view;
2727

28-
std::vector<ControlState> stateStack;
28+
ControlState state;
2929
std::vector<Coordinate> clickHistory;
3030

3131
GameController(const GameController& o) : model(o.model), view(o.view) {} //deleted

resources/graphics.conf

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,71 @@ font.size = 50
66
screen.width = 1280
77
screen.height = 720
88

9+
# Buttons
10+
screen.roadButton.text=Road |
11+
screen.roadButton.area=((0,0),(0.1,0.1))
12+
13+
screen.cityButton.text=City |
14+
screen.cityButton.area=((0.1,0),(0.2,0.1))
15+
16+
screen.settlementButton.text=Settlement
17+
screen.settlementButton.area=((0.20,0.0),(0.33,0.1))
18+
19+
screen.wonderButton.text=|Wonder
20+
screen.wonderButton.area=((0.55,0.0),(0.65,0.1))
21+
22+
screen.endTurnButton.text=End Turn
23+
screen.endTurnButton.area=((0,0.3),(0.1,0.4))
24+
25+
screen.players.topY=0.82
26+
screen.players.width=0.15
27+
screen.players.height=0.05
28+
screen.players.right=1.0
29+
30+
screen.bankButton.text=Bank
31+
screen.bankButton.area=((0,0.8),(0.1,0.9))
32+
33+
screen.cancelButton.text=Cancel
34+
screen.cancelButton.area=((.92,.96),(1.0,1.0))
35+
36+
screen.developmentCardButton.text=Development Cards
37+
screen.developmentCardButton.area=((.85,.23),(1,.30))
38+
39+
screen.roadBuildingButton.text=Road Building
40+
screen.roadBuildingButton.area=((0.85,0.0),(0.97,0.05))
41+
42+
screen.knightButton.text=Knight
43+
screen.knightButton.area=((0.85,0.05),(0.97,0.10))
44+
45+
screen.yearOfPlentyButton.text=Year of Plenty
46+
screen.yearOfPlentyButton.area=((0.85,0.10),(0.97,0.15))
47+
48+
screen.monopolyButton.text=Monopoly
49+
screen.monopolyButton.area=((0.85,0.15),(0.97,0.20))
50+
51+
screen.victoryPointButton.text=Victory Point
52+
screen.victoryPointButton.area=((0.85,0.20),(0.97,0.25))
53+
54+
screen.woodButton.text=Wood
55+
screen.woodButton.area=((.85,.30),(.97,.35))
56+
57+
screen.sheepButton.text=Sheep
58+
screen.sheepButton.area=((.85,.35),(.97,.40))
59+
60+
screen.oreButton.text=Ore
61+
screen.oreButton.area=((.85,.40),(.97,.45))
62+
63+
screen.brickButton.text=Brick
64+
screen.brickButton.area=((.85,.45),(.97,.50))
65+
66+
screen.wheatButton.text=Wheat
67+
screen.wheatButton.area=((.85,.50),(.97,.55))
68+
69+
screen.showTotalButton.text=Show Totals
70+
screen.showTotalButton.area=((.85,.55),(.97,.60))
71+
72+
screen.board.area=((0,0),(1,1))
73+
974
# Trading view screen coordinates
1075
screen.tradingView.bottomLeft = (0.1,0.1)
1176
screen.tradingView.topRight = (0.9,0.9)

src/Config.cpp

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ ConfigValue::operator string() const {
3535
return value;
3636
}
3737

38+
3839
/**
39-
* Convert the ConfigValue into a game Coordinate.
40-
* @throws runtime_error If the value cannot be converted.
41-
* @return The text of the ConfigValue, interpreted as a game Coordinate.
40+
* Read a pair (S,T) in from a stream.
41+
* @throws runtime_error If the pair is not in the form (S,T).
42+
* @param stream The stream to read in from.
43+
* @param ret The pair to read into.
4244
*/
43-
ConfigValue::operator Coordinate() const {
44-
stringstream stream(value);
45-
Coordinate ret;
45+
template<class S, class T>
46+
void readPair(std::stringstream& stream, std::pair<S, T>& ret) {
4647
char c = stream.get();
4748
if(c != '(') {
4849
throw runtime_error("Attempt to read a coordinate out of a non-coordinate value");
@@ -53,6 +54,21 @@ ConfigValue::operator Coordinate() const {
5354
throw runtime_error("Attempt to read a coordinate out of a non-coordinate value");
5455
}
5556
stream >> ret.second;
57+
c = stream.get();
58+
if(c != ')') {
59+
throw runtime_error("Attempt to read a coordinate out of a non-coordinate value");
60+
}
61+
}
62+
63+
/**
64+
* Convert the ConfigValue into a game Coordinate.
65+
* @throws runtime_error If the value cannot be converted.
66+
* @return The text of the ConfigValue, interpreted as a game Coordinate.
67+
*/
68+
ConfigValue::operator Coordinate() const {
69+
stringstream stream(value);
70+
Coordinate ret;
71+
readPair(stream, ret);
5672
return ret;
5773
}
5874

@@ -64,16 +80,28 @@ ConfigValue::operator Coordinate() const {
6480
ConfigValue::operator ScreenCoordinate() const {
6581
stringstream stream(value);
6682
ScreenCoordinate ret;
83+
readPair(stream, ret);
84+
return ret;
85+
}
86+
87+
/**
88+
* Convert the ConfigValue into a pair of ScreenCoordinates.
89+
* @throws runtime_error If the value cannot be converted.
90+
* @return The text of the ConfigValue, interpreted as a pair of ScreenCoordinates.
91+
*/
92+
ConfigValue::operator std::pair<ScreenCoordinate, ScreenCoordinate>() const {
93+
stringstream stream(value);
94+
std::pair<ScreenCoordinate, ScreenCoordinate> ret;
6795
char c = stream.get();
6896
if(c != '(') {
6997
throw runtime_error("Attempt to read a coordinate out of a non-coordinate value");
7098
}
71-
stream >> ret.first;
99+
readPair(stream, ret.first);
72100
c = stream.get();
73101
if(c != ',') {
74102
throw runtime_error("Attempt to read a coordinate out of a non-coordinate value");
75103
}
76-
stream >> ret.second;
104+
readPair(stream, ret.second);
77105
return ret;
78106
}
79107

@@ -134,7 +162,7 @@ void Config::init(istream& source) {
134162
const ConfigValue& Config::operator[](const string& name) const {
135163
auto it = values.find(name);
136164
if(it == values.end()) {
137-
throw runtime_error("No such key in the config");
165+
throw runtime_error("No such key in the config: \"" + name + "\"");
138166
} else {
139167
return it->second;
140168
}

0 commit comments

Comments
 (0)