Skip to content

Commit 883d734

Browse files
author
ankit21
committed
Merge remote-tracking branch 'origin/master' into refactor_deck
2 parents ca768ba + 268eb2c commit 883d734

File tree

7 files changed

+239
-92
lines changed

7 files changed

+239
-92
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ $(EXECUTABLE): $(ALLFILES)
2020
.PHONY: tests
2121
tests: $(EXECUTABLE)
2222
cd tests && $(MAKE)
23+
tests/main.test
2324

2425
.PHONY: clean
2526
clean:

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: 81 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,90 @@
11
# Font settings
2-
font.path=resources/ComicNeue-Bold.ttf
3-
font.size=50
2+
font.path = resources/ComicNeue-Bold.ttf
3+
font.size = 50
44

55
# General window settings
6-
screen.width=1280
7-
screen.height=720
6+
screen.width = 1280
7+
screen.height = 720
8+
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))
873

974
# Trading view screen coordinates
10-
screen.tradingView.bottomLeft=(0.1,0.1)
11-
screen.tradingView.topRight=(0.9,0.9)
75+
screen.tradingView.bottomLeft = (0.1,0.1)
76+
screen.tradingView.topRight = (0.9,0.9)
1277

13-
screen.tradingView.tradeButton.bottomLeft=(0.7,0.1)
14-
screen.tradingView.tradeButton.topRight=(0.9,0.2)
78+
screen.tradingView.tradeButton.bottomLeft = (0.7,0.1)
79+
screen.tradingView.tradeButton.topRight = (0.9,0.2)
1580

16-
screen.tradingView.cancelButton.bottomLeft=(0.1,0.1)
17-
screen.tradingView.cancelButton.topRight=(0.3,0.2)
81+
screen.tradingView.cancelButton.bottomLeft = (0.1,0.1)
82+
screen.tradingView.cancelButton.topRight = (0.3,0.2)
1883

19-
screen.tradingView.resources.height=0.13
20-
screen.tradingView.resources.leftX=0.3
21-
screen.tradingView.resources.rightX=0.6
22-
screen.tradingView.resources.bottomY=0.2
84+
screen.tradingView.resources.height = 0.13
85+
screen.tradingView.resources.leftX = 0.3
86+
screen.tradingView.resources.rightX = 0.6
87+
screen.tradingView.resources.bottomY = 0.2
2388

24-
screen.tradingView.players.bottomLeft=(0.1,0.8)
25-
screen.tradingView.players.topRight=(0.9,0.9)
89+
screen.tradingView.players.bottomLeft = (0.1,0.8)
90+
screen.tradingView.players.topRight = (0.9,0.9)

src/Config.cpp

Lines changed: 43 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

@@ -114,7 +142,13 @@ void Config::init(istream& source) {
114142
continue;
115143
}
116144
string name = line.substr(0, line.find('='));
145+
while(name[name.size()-1] == ' ' || name[name.size()-1] == '\t') {
146+
name = name.substr(0, name.size()-1);
147+
}
117148
string value = line.substr(line.find('=') + 1);
149+
while(value[0] == ' ' || value[0] == '\t') {
150+
value = value.substr(1);
151+
}
118152
values.insert(std::make_pair(name, ConfigValue(value)));
119153
}
120154
}
@@ -128,7 +162,7 @@ void Config::init(istream& source) {
128162
const ConfigValue& Config::operator[](const string& name) const {
129163
auto it = values.find(name);
130164
if(it == values.end()) {
131-
throw runtime_error("No such key in the config");
165+
throw runtime_error("No such key in the config: \"" + name + "\"");
132166
} else {
133167
return it->second;
134168
}

0 commit comments

Comments
 (0)