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
@@ -35,6 +33,7 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
3533 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 ()));
3634 playerTopY -= 0.05 ;
3735 }
36+ view.addElement (makeViewButtonText (std::bind (&GameController::handleBankClick, this , _1), {{0 , 0.8 }, {0.1 , 0.9 }}, font, fontSize, " Bank" ));
3837
3938 view.addElement (makeViewButtonText (std::bind (&GameController::handleCancelButtonEvent, this , _1), {{.92 , .96 }, {1.0 , 1.0 }}, font, fontSize, " Cancel" ));
4039
@@ -50,8 +49,9 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
5049 view.addElement (makeViewButtonText (std::bind (&GameController::handleOreButtonEvent, this , _1), {{.85 , .45 }, {.97 , .50 }}, font, fontSize, " Ore " ));
5150 view.addElement (makeViewButtonText (std::bind (&GameController::handleBrickButtonEvent, this , _1), {{.85 , .50 }, {.97 , .55 }}, font, fontSize, " Brick " ));
5251 view.addElement (makeViewButtonText (std::bind (&GameController::handleWheatButtonEvent, this , _1), {{.85 , .55 }, {.97 , .60 }}, font, fontSize, " Wheat " ));
53-
54-
52+
53+ view.addElement (100 , makeViewButton (std::bind (&GameController::handleBoardEvent, this , _1), {{0 , 0 }, {1 , 1 }}));
54+
5555 stateStack.push_back (BASESTATE);
5656}
5757
@@ -448,7 +448,7 @@ bool GameController::handlePlayerClick(ScreenCoordinate coord, Player& player) {
448448 return true ;
449449 });
450450
451- view.addElement (priority, std::unique_ptr<ViewElement>(new TradingView (initiating, receiving, tradeFunction, cancelFunction, initial)));
451+ view.addElement (priority, std::unique_ptr<ViewElement>(new TradingView (initiating. getName () , receiving. getName () , tradeFunction, cancelFunction, initial)));
452452 std::cout << player.getName () << std::endl;
453453 return true ;
454454
@@ -476,6 +476,38 @@ bool GameController::handlePlayerClick(ScreenCoordinate coord, Player& player) {
476476
477477}
478478
479+ /* *
480+ * Handle a player beginning a trade with the bank.
481+ */
482+ bool GameController::handleBankClick (ScreenCoordinate screenCoord) {
483+
484+ auto priority = -10 ;
485+
486+ auto tradeFunction = [this , priority](std::array<int , 5 > offer, ScreenCoordinate coord) {
487+ std::array<int , 5 > splitOffer;
488+ std::array<int , 5 > splitDemand;
489+ for (int i = 0 ; i < 5 ; i++) {
490+ std::cout << " offer " << i << " " << offer[i] << std::endl;
491+ splitOffer[i] = offer[i] > 0 ? 0 : -offer[i];
492+ splitDemand[i] = offer[i] < 0 ? 0 : offer[i];
493+ }
494+ if (model.getCurrentPlayer ().makeBankTrade (splitOffer, splitDemand)) {
495+ view.removeElement (priority);
496+ }
497+ return true ;
498+ };
499+
500+ auto cancelFunction = [this , priority](ScreenCoordinate coord) {
501+ view.removeElement (priority);
502+ return true ;
503+ };
504+
505+ view.addElement (priority, std::unique_ptr<ViewElement>(new TradingView (model.getCurrentPlayer ().getName (), " Bank" , tradeFunction, cancelFunction, {0 , 0 , 0 , 0 , 0 })));
506+
507+ return true ;
508+ }
509+
510+
479511/* *
480512 * Handle a trade offer from a player.
481513 * @param coord The coordinate clicked on to initiate the trade.
@@ -506,7 +538,7 @@ bool GameController::handleTradeOffer(ScreenCoordinate coord, Player& initiating
506538 return true ;
507539 });
508540
509- view.addElement (priority, std::unique_ptr<ViewElement>(new TradingView (initiating, receiving, tradeFunction, cancelFunction, counterOffer)));
541+ view.addElement (priority, std::unique_ptr<ViewElement>(new TradingView (initiating. getName () , receiving. getName () , tradeFunction, cancelFunction, counterOffer)));
510542 }
511543 return true ;
512544}
@@ -584,4 +616,3 @@ bool GameController::handleBrickButtonEvent(ScreenCoordinate coord){
584616 return false ;
585617
586618}
587-
0 commit comments