@@ -23,10 +23,10 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
2323 auto font = getGraphicsConfig ()[" font.path" ];
2424 auto fontSize = getGraphicsConfig ()[" font.size" ];
2525
26- view.addElement (makeViewButtonText (std::bind (&GameController::handleRoadButtonEvent, this , _1), {{0 , 0 }, {0.1 , 0.1 }}, font, fontSize, " Road" ));
27- view.addElement (makeViewButtonText (std::bind (&GameController::handleSettlementButtonEvent , this , _1), {{0 , 0.1 }, {0.1 , 0.2 }}, font, fontSize, " Stlm " ));
28- view.addElement (makeViewButtonText (std::bind (&GameController::handleCityButtonEvent , this , _1), {{0 , 0.2 }, {0.1 , 0.3 }}, font, fontSize, " City " ));
29- view.addElement (makeViewButtonText (std::bind (&GameController::nextTurn, this , _1), {{0 , 0.3 }, {0.1 , 0.4 }}, font, fontSize, " Turn" ));
26+ view.addElement (makeViewButtonText (std::bind (&GameController::handleRoadButtonEvent, this , _1), {{0 , 0 }, {0.1 , 0.10 }}, font, fontSize, " Road | " ));
27+ view.addElement (makeViewButtonText (std::bind (&GameController::handleCityButtonEvent , this , _1), {{0.10 , 0.0 }, {0.20 , 0.1 }}, font, fontSize, " City | " ));
28+ view.addElement (makeViewButtonText (std::bind (&GameController::handleSettlementButtonEvent , this , _1), {{0.20 , 0.0 }, {0.33 , 0.1 }}, font, fontSize, " Settlement " ));
29+ view.addElement (makeViewButtonText (std::bind (&GameController::nextTurn, this , _1), {{0 , 0.3 }, {0.1 , 0.4 }}, font, fontSize, " End Turn" ));
3030
3131 auto playerTopY = 0.9 ;
3232 for (auto i = 0 ; i < model.getNoOfPlayers (); i++) {
@@ -36,7 +36,7 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
3636 playerTopY -= 0.05 ;
3737 }
3838
39- view.addElement (makeViewButtonColor (std::bind (&GameController::handleCancelButtonEvent, this , _1), {{.95 , .95 }, {1.0 , 1.0 }}, std::make_tuple ( 1 . f , 0 . 0f , 0 . f ) ));
39+ view.addElement (makeViewButtonText (std::bind (&GameController::handleCancelButtonEvent, this , _1), {{.92 , .96 }, {1.0 , 1.0 }}, font, fontSize, " Cancel " ));
4040
4141 view.addElement (makeViewButtonText (std::bind (&GameController::handleBuyDevelopmentCardButtonEvent, this , _1), {{.85 , .23 }, {1 , .30 }}, font, fontSize, " Development Cards" ));
4242 view.addElement (makeViewButtonText (std::bind (&GameController::handleRoadCardButtonEvent, this , _1), {{0.85 , 0.0 }, {0.97 , 0.05 }}, font, fontSize, " Road Building " ));
@@ -45,6 +45,11 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
4545 view.addElement (makeViewButtonText (std::bind (&GameController::handleMonopolyCardButtonEvent, this , _1), {{0.85 , 0.15 }, {0.97 , 0.20 }}, font, fontSize, " Monopoly " ));
4646 view.addElement (makeViewButtonText (std::bind (&GameController::handleVictoryPointCardButtonEvent, this , _1), {{0.85 , 0.20 }, {0.97 , 0.25 }}, font, fontSize, " Victory Point " ));
4747
48+ view.addElement (makeViewButtonText (std::bind (&GameController::handleWoodButtonEvent, this , _1), {{.85 , .35 }, {.97 , .40 }}, font, fontSize, " Wood " ));
49+ view.addElement (makeViewButtonText (std::bind (&GameController::handleSheepButtonEvent, this , _1), {{.85 , .40 }, {.97 , .45 }}, font, fontSize, " Sheep " ));
50+ view.addElement (makeViewButtonText (std::bind (&GameController::handleOreButtonEvent, this , _1), {{.85 , .45 }, {.97 , .50 }}, font, fontSize, " Ore " ));
51+ view.addElement (makeViewButtonText (std::bind (&GameController::handleBrickButtonEvent, this , _1), {{.85 , .50 }, {.97 , .55 }}, font, fontSize, " Brick " ));
52+ view.addElement (makeViewButtonText (std::bind (&GameController::handleWheatButtonEvent, this , _1), {{.85 , .55 }, {.97 , .60 }}, font, fontSize, " Wheat " ));
4853
4954
5055 stateStack.push_back (BASESTATE);
@@ -149,6 +154,7 @@ bool GameController::nextTurn(ScreenCoordinate) {
149154}
150155
151156
157+
152158/* *
153159 * Handles a click that is actually on the tiles of the board. Either constructs a road or a settlement based on the control buttons the user has clicked.
154160 * @param screenCoord Where the user clicked on screen.
@@ -165,7 +171,7 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
165171 } else {
166172 if (model.buyRoad (getLastClick (), coord, model.getCurrentPlayer ()));
167173 {
168- popState ( );
174+ handleCancelButtonEvent (screenCoord );
169175 }
170176 clearClickHistory ();
171177 }
@@ -186,30 +192,23 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
186192 }
187193 break ;
188194 case KNIGHT_DEVCARD:
189- // model.getCurrentPlayer().playKnight(coord, opponent);
190- popState ();
191- break ;
192- case YEAROFPLENTY_DEVCARD:
193- model.getCurrentPlayer ().playYearOfPlenty (model.getResourceTile (coord).getType ());
194- popState ();
195- break ;
196- case MONOPOLY_DEVCARD:
197- model.getCurrentPlayer ().playYearOfPlenty (model.getResourceTile (coord).getType ());
195+ storeClick (coord);
196+ view.setControlStateText (" Select a player around that tile to steal from (Select yourself if you don't want to rob anyone)" );
198197 popState ();
199198 break ;
200199 case VICTORYPOINT_DEVCARD:
201200 model.getCurrentPlayer ().playVictoryCard ();
202- popState ( );
201+ handleCancelButtonEvent (screenCoord );
203202 break ;
204203 case BUILDSETTLEMENT:
205204 std::cout << " attempting to buy a settlement" << std::endl;
206205 model.buySettlement (coord, model.getCurrentPlayer ());
207- popState ( );
206+ handleCancelButtonEvent (screenCoord );
208207 break ;
209208 case BUILDCITY:
210209 std::cout << " attempting to build a city" << std::endl;
211210 model.buyUpgradeOnSettlement (coord, model.getCurrentPlayer ());
212- popState ( );
211+ handleCancelButtonEvent (screenCoord );
213212 break ;
214213 default :
215214 break ;
@@ -225,6 +224,7 @@ bool GameController::handleCancelButtonEvent(ScreenCoordinate){
225224 while (getState () != BASESTATE){
226225 popState ();
227226 }
227+ view.setControlStateText (" " );
228228 clearClickHistory ();
229229 return true ;
230230}
@@ -238,8 +238,9 @@ bool GameController::handleCancelButtonEvent(ScreenCoordinate){
238238bool GameController::handleRoadButtonEvent (ScreenCoordinate coord) {
239239 clearClickHistory ();
240240 if (getState () != BASESTATE){
241- return true ;
241+ return false ;
242242 }
243+ view.setControlStateText (" Click two adjacent corner points to place a road. (1Br and 1Wd)" );
243244 pushState (BUILDROAD);
244245 return true ;
245246}
@@ -251,8 +252,9 @@ bool GameController::handleRoadButtonEvent(ScreenCoordinate coord) {
251252 */
252253bool GameController::handleSettlementButtonEvent (ScreenCoordinate coord) {
253254 if (getState () != BASESTATE){
254- return true ;
255+ return false ;
255256 }
257+ view.setControlStateText (" Click on a corner tile to build a settlement there. (1Br, 1Wh, 1Wd, and 1Sh)" );
256258 pushState (BUILDSETTLEMENT);
257259 return true ;
258260}
@@ -263,9 +265,12 @@ bool GameController::handleSettlementButtonEvent(ScreenCoordinate coord) {
263265 * @return Whether this event was handled by this element. Always true.
264266 */
265267bool GameController::handleCityButtonEvent (ScreenCoordinate coord) {
266- if (getState () = = BASESTATE) {
267- pushState (BUILDCITY) ;
268+ if (getState () ! = BASESTATE) {
269+ return false ;
268270 }
271+
272+ view.setControlStateText (" Click on a settlement to upgrade it to a city. (3Wh and 2Ore)" );
273+ pushState (BUILDCITY);
269274 return true ;
270275}
271276
@@ -280,6 +285,8 @@ bool GameController::handleRoadCardButtonEvent(ScreenCoordinate coord){
280285 return true ;
281286 }
282287 clearClickHistory ();
288+
289+ view.setControlStateText (" Playing Road Building Card: Click on adjacent points for the roads you want." );
283290 pushState (BUILDROAD_DEVCARD);
284291 return true ;
285292}
@@ -320,6 +327,8 @@ bool GameController::handleKnightCardButtonEvent(ScreenCoordinate coord){
320327 if (getState () != BASESTATE){
321328 return true ;
322329 }
330+
331+ view.setControlStateText (" Select a tile that you want to place the robber on" );
323332 pushState (KNIGHT_DEVCARD);
324333 return true ;
325334}
@@ -333,6 +342,8 @@ bool GameController::handleYearOfPlentyCardButtonEvent(ScreenCoordinate coord){
333342 if (getState () != BASESTATE){
334343 return true ;
335344 }
345+
346+ view.setControlStateText (" Playing Year of Plenty Card: Click on the resource you want on the side of the screen" );
336347 pushState (YEAROFPLENTY_DEVCARD);
337348 return true ;
338349}
@@ -346,6 +357,7 @@ bool GameController::handleMonopolyCardButtonEvent(ScreenCoordinate coord){
346357 if (getState () != BASESTATE){
347358 return true ;
348359 }
360+ view.setControlStateText (" Playing Monopoly Card: Click on the resource you want on the side of the screen" );
349361 pushState (MONOPOLY_DEVCARD);
350362 return true ;
351363}
@@ -378,28 +390,33 @@ auto negativeArr(std::array<int, size> arr) -> std::array<int, size> {
378390 * @param player The player whose name was clicked on.
379391 */
380392bool GameController::handlePlayerClick (ScreenCoordinate coord, Player& player) {
381- using namespace std ::placeholders;
382- Player& initiating = *model.getPlayers ()[0 ];
383- Player& receiving = player;
384- auto priority = -10 ;
385-
386- std::array<int , 5 > initial{{0 , 0 , 0 , 0 , 0 }};
387-
388- // std::function<bool(std::array<int, 5>, ScreenCoordinate)> tradeFunction(std::bind(&GameController::handleTradeOffer, this, _2, std::ref(initiating), _1, std::ref(receiving)));
389- std::function<bool (std::array<int , 5 >, ScreenCoordinate)> tradeFunction ([this , &initiating, &receiving](std::array<int , 5 > offer, ScreenCoordinate coord) {
393+ if (getState () == BASESTATE){
394+ using namespace std ::placeholders;
395+ Player& initiating = *model.getPlayers ()[0 ];
396+ Player& receiving = player;
397+ auto priority = -10 ;
398+
390399 std::array<int , 5 > initial{{0 , 0 , 0 , 0 , 0 }};
391- std::array<int , 5 > reverseOffer = negativeArr<5 >(offer);
392- handleTradeOffer (coord, receiving, initial, initiating, reverseOffer);
393- return true ;
394- });
395- std::function<bool (ScreenCoordinate)> cancelFunction ([this , priority](ScreenCoordinate coord) {
396- view.removeElement (priority);
400+
401+ // std::function<bool(std::array<int, 5>, ScreenCoordinate)> tradeFunction(std::bind(&GameController::handleTradeOffer, this, _2, std::ref(initiating), _1, std::ref(receiving)));
402+ std::function<bool (std::array<int , 5 >, ScreenCoordinate)> tradeFunction ([this , &initiating, &receiving](std::array<int , 5 > offer, ScreenCoordinate coord) {
403+ std::array<int , 5 > initial{{0 , 0 , 0 , 0 , 0 }};
404+ std::array<int , 5 > reverseOffer = negativeArr<5 >(offer);
405+ handleTradeOffer (coord, receiving, initial, initiating, reverseOffer);
406+ return true ;
407+ });
408+ std::function<bool (ScreenCoordinate)> cancelFunction ([this , priority](ScreenCoordinate coord) {
409+ view.removeElement (priority);
410+ return true ;
411+ });
412+
413+ view.addElement (priority, std::unique_ptr<ViewElement>(new TradingView (initiating, receiving, tradeFunction, cancelFunction, initial)));
414+ std::cout << player.getName () << std::endl;
397415 return true ;
398- });
416+ }else if (getState () == KNIGHT_DEVCARD){
417+ model.getCurrentPlayer ().playKnight (getPastClick (0 ), player);
418+ }
399419
400- view.addElement (priority, std::unique_ptr<ViewElement>(new TradingView (initiating, receiving, tradeFunction, cancelFunction, initial)));
401- std::cout << player.getName () << std::endl;
402- return true ;
403420}
404421
405422/* *
@@ -437,3 +454,58 @@ bool GameController::handleTradeOffer(ScreenCoordinate coord, Player& initiating
437454 return true ;
438455}
439456
457+ bool GameController::handleWoodButtonEvent (ScreenCoordinate coord){
458+ if (getState () == YEAROFPLENTY_DEVCARD){
459+ model.getCurrentPlayer ().playYearOfPlenty (WOOD);
460+ return handleCancelButtonEvent (coord);
461+ }else if (getState () == MONOPOLY_DEVCARD){
462+ model.getCurrentPlayer ().playMonopoly (WOOD);
463+ return handleCancelButtonEvent (coord);
464+ }
465+ return false ;
466+ }
467+ bool GameController::handleSheepButtonEvent (ScreenCoordinate coord){
468+ if (getState () == YEAROFPLENTY_DEVCARD){
469+ model.getCurrentPlayer ().playYearOfPlenty (SHEEP);
470+ return handleCancelButtonEvent (coord);
471+ }else if (getState () == MONOPOLY_DEVCARD){
472+ model.getCurrentPlayer ().playMonopoly (SHEEP);
473+ return handleCancelButtonEvent (coord);
474+ }
475+ return false ;
476+
477+ }
478+ bool GameController::handleWheatButtonEvent (ScreenCoordinate coord){
479+ if (getState () == YEAROFPLENTY_DEVCARD){
480+ model.getCurrentPlayer ().playYearOfPlenty (WHEAT);
481+ return handleCancelButtonEvent (coord);
482+ }else if (getState () == MONOPOLY_DEVCARD){
483+ model.getCurrentPlayer ().playMonopoly (WHEAT);
484+ return handleCancelButtonEvent (coord);
485+ }
486+ return false ;
487+
488+ }
489+ bool GameController::handleOreButtonEvent (ScreenCoordinate coord){
490+ if (getState () == YEAROFPLENTY_DEVCARD){
491+ model.getCurrentPlayer ().playYearOfPlenty (STONE);
492+ return handleCancelButtonEvent (coord);
493+ }else if (getState () == MONOPOLY_DEVCARD){
494+ model.getCurrentPlayer ().playMonopoly (STONE);
495+ return handleCancelButtonEvent (coord);
496+ }
497+ return false ;
498+
499+ }
500+ bool GameController::handleBrickButtonEvent (ScreenCoordinate coord){
501+ if (getState () == YEAROFPLENTY_DEVCARD){
502+ model.getCurrentPlayer ().playYearOfPlenty (BRICK);
503+ return handleCancelButtonEvent (coord);
504+ }else if (getState () == MONOPOLY_DEVCARD){
505+ model.getCurrentPlayer ().playMonopoly (BRICK);
506+ return handleCancelButtonEvent (coord);
507+ }
508+ return false ;
509+
510+ }
511+
0 commit comments