1818GameController::GameController (GameBoard& model, GameView& view) : model(model), view(view) {
1919 using namespace std ::placeholders;
2020
21- view.addElement (makeViewButton (std::bind (&GameController::handleBoardEvent, this , _1), {{0 , 0 }, {1 , 1 }}));
22-
2321 auto font = getGraphicsConfig ()[" font.path" ];
2422 auto fontSize = getGraphicsConfig ()[" font.size" ];
2523
@@ -36,6 +34,7 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
3634 view.addElement (makeViewButtonText (std::bind (&GameController::handlePlayerClick, this , _1, std::ref (player)), {{1.0 - width, playerTopY - 0.05 }, {1.0 , playerTopY}}, font, fontSize, player.getName ()));
3735 playerTopY -= 0.05 ;
3836 }
37+ view.addElement (makeViewButtonText (std::bind (&GameController::handleBankClick, this , _1), {{0 , 0.8 }, {0.1 , 0.9 }}, font, fontSize, " Bank" ));
3938
4039 view.addElement (makeViewButtonText (std::bind (&GameController::handleCancelButtonEvent, this , _1), {{.92 , .96 }, {1.0 , 1.0 }}, font, fontSize, " Cancel" ));
4140
@@ -45,7 +44,7 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
4544 view.addElement (makeViewButtonText (std::bind (&GameController::handleYearOfPlentyCardButtonEvent, this , _1), {{0.85 , 0.10 }, {0.97 , 0.15 }}, font, fontSize, " Year of Plenty " ));
4645 view.addElement (makeViewButtonText (std::bind (&GameController::handleMonopolyCardButtonEvent, this , _1), {{0.85 , 0.15 }, {0.97 , 0.20 }}, font, fontSize, " Monopoly " ));
4746 view.addElement (makeViewButtonText (std::bind (&GameController::handleVictoryPointCardButtonEvent, this , _1), {{0.85 , 0.20 }, {0.97 , 0.25 }}, font, fontSize, " Victory Point " ));
48-
47+
4948 view.addElement (makeViewButtonText (std::bind (&GameController::handleWoodButtonEvent, this , _1), {{.85 , .30 }, {.97 , .35 }}, font, fontSize, " Wood " ));
5049 view.addElement (makeViewButtonText (std::bind (&GameController::handleSheepButtonEvent, this , _1), {{.85 , .35 }, {.97 , .40 }}, font, fontSize, " Sheep " ));
5150 view.addElement (makeViewButtonText (std::bind (&GameController::handleOreButtonEvent, this , _1), {{.85 , .40 }, {.97 , .45 }}, font, fontSize, " Ore " ));
@@ -54,7 +53,7 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
5453
5554 view.addElement (makeViewButtonText (std::bind (&GameController::viewCardTotals, this , _1), {{.85 , .55 }, {.97 , .60 }}, font, fontSize, " Show Totals" ));
5655
57-
56+ view. addElement ( 100 , makeViewButton ( std::bind (&GameController::handleBoardEvent, this , _1), {{ 0 , 0 }, { 1 , 1 }}));
5857 stateStack.push_back (BASESTATE);
5958}
6059
@@ -491,7 +490,7 @@ bool GameController::handlePlayerClick(ScreenCoordinate coord, Player& player) {
491490 return true ;
492491 });
493492
494- view.addElement (priority, std::unique_ptr<ViewElement>(new TradingView (initiating, receiving, tradeFunction, cancelFunction, initial)));
493+ view.addElement (priority, std::unique_ptr<ViewElement>(new TradingView (initiating. getName () , receiving. getName () , tradeFunction, cancelFunction, initial)));
495494 std::cout << player.getName () << std::endl;
496495 return true ;
497496
@@ -519,6 +518,37 @@ bool GameController::handlePlayerClick(ScreenCoordinate coord, Player& player) {
519518 return true ;
520519}
521520
521+ /* *
522+ * Handle a player beginning a trade with the bank.
523+ */
524+ bool GameController::handleBankClick (ScreenCoordinate screenCoord) {
525+
526+ auto priority = -10 ;
527+
528+ auto tradeFunction = [this , priority](std::array<int , 5 > offer, ScreenCoordinate coord) {
529+ std::array<int , 5 > splitOffer;
530+ std::array<int , 5 > splitDemand;
531+ for (int i = 0 ; i < 5 ; i++) {
532+ splitOffer[i] = offer[i] > 0 ? 0 : -offer[i];
533+ splitDemand[i] = offer[i] < 0 ? 0 : offer[i];
534+ }
535+ if (model.getCurrentPlayer ().makeBankTrade (splitOffer, splitDemand)) {
536+ view.removeElement (priority);
537+ }
538+ return true ;
539+ };
540+
541+ auto cancelFunction = [this , priority](ScreenCoordinate coord) {
542+ view.removeElement (priority);
543+ return true ;
544+ };
545+ std::array<int , 5 > initial{{0 , 0 , 0 , 0 , 0 }};
546+ view.addElement (priority, std::unique_ptr<ViewElement>(new TradingView (model.getCurrentPlayer ().getName (), " Bank" , tradeFunction, cancelFunction, initial)));
547+
548+ return true ;
549+ }
550+
551+
522552/* *
523553 * Handle a trade offer from a player.
524554 * @param coord The coordinate clicked on to initiate the trade.
@@ -549,7 +579,7 @@ bool GameController::handleTradeOffer(ScreenCoordinate coord, Player& initiating
549579 return true ;
550580 });
551581
552- view.addElement (priority, std::unique_ptr<ViewElement>(new TradingView (initiating, receiving, tradeFunction, cancelFunction, counterOffer)));
582+ view.addElement (priority, std::unique_ptr<ViewElement>(new TradingView (initiating. getName () , receiving. getName () , tradeFunction, cancelFunction, counterOffer)));
553583 }
554584 return true ;
555585}
@@ -627,4 +657,3 @@ bool GameController::handleBrickButtonEvent(ScreenCoordinate coord){
627657 return false ;
628658
629659}
630-
0 commit comments