public override void enableEventObjects()
 {
     tradeWindow = new TradeWindow();
     tradeWindow.loadYearOfPlenty(theBoard.currentPlayer);
     tradeWindow.Show();
     tradeWindow.Closing += executeUpdate;
 }
 public void bankTrade(Object sender, EventArgs e)
 {
     disableEventObjects();
     tradeWindow = new TradeWindow();
     tradeWindow.loadBankTrade(theBoard.currentPlayer);
     tradeWindow.Closing += onTradeEnded;
     currentState         = State.Trade;
     tradeWindow.Show();
 }
Ejemplo n.º 3
0
        public override void executeUpdate(Object sender, EventArgs e)
        {
            switch (state)
            {
            case 0:

                if (playersToGiveUpCards.Count() > 0)
                {
                    theBoard.currentPlayer = playersToGiveUpCards[0];
                    MessageBox.Show(playersToGiveUpCards[0].getName() + " is holding more than 7 cards. Please select ones you wish to give up.");
                    //make the player at index 0 give up their cards
                    disableEventObjects();
                    TradeWindow tradeWindow = new TradeWindow();
                    tradeWindow.loadPlayerResourceLoss(playersToGiveUpCards[0]);
                    tradeWindow.Closing += finishedStealing;
                    tradeWindow.Show();
                    playersToGiveUpCards.Remove(playersToGiveUpCards[0]);
                }
                else
                {
                    theBoard.currentPlayer = activePlayer;
                    state++;
                    executeUpdate(sender, e);
                }
                break;

            case 1:
                //Run the regular robber event.
                ThiefEvt evt = new ThiefEvt();
                disableEventObjects();
                evt.beginExecution(theBoard, this);
                state++;
                break;

            case 2:
                endExecution();
                break;
            }
        }
        public override void executeUpdate(Object sender, EventArgs e)
        {
            switch (currentState)
            {
            case State.Wait:
                if (sender == theBoard.btnEndTurn)
                {
                    //End turn.
                    theBoard.addEventText(UserMessages.PlayerEndedTurn(theBoard.currentPlayer));
                    endExecution();
                    return;
                }
                else if (sender is Settlement)
                {
                    Settlement location = (Settlement)sender;
                    try
                    {
                        //Try to build the settlement/upgrade city.
                        ((Settlement)sender).buildSettlement(theBoard.currentPlayer, true, true);
                        //Take resources
                        if (location.city())
                        {
                            //take city resources
                            Board.TheBank.takePayment(theBoard.currentPlayer, Bank.CITY_COST);
                            theBoard.addEventText(UserMessages.PlayerBuiltACity(theBoard.currentPlayer));
                            theBoard.checkForWinner();
                        }
                        else
                        {
                            //take settlement resources
                            Board.TheBank.takePayment(theBoard.currentPlayer, Bank.SETTLEMENT_COST);
                            theBoard.addEventText(UserMessages.PlayerPlacedASettlement(theBoard.currentPlayer));
                            theBoard.checkForWinner();
                        }
                    } catch (BuildError be)
                    {
                        theBoard.addEventText(be.Message);
                    }
                }
                else if (sender is Road)
                {
                    //Try to build the road
                    try
                    {
                        ((Road)sender).buildRoad(theBoard.currentPlayer, true);
                        //Take the resources.
                        Board.TheBank.takePayment(theBoard.currentPlayer, Bank.ROAD_COST);
                        theBoard.addEventText(UserMessages.PlayerPlacedARoad(theBoard.currentPlayer));
                        //RUN LONGEST ROAD CHECK
                        theBoard.checkForWinner();
                    } catch (BuildError be)
                    {
                        theBoard.addEventText(be.Message);
                    }
                }
                else if (sender == theBoard.pbBuildDevelopmentCard)
                {
                    //We want to give the player a development card.
                    try
                    {
                        DevelopmentCard devC = Board.TheBank.purchaseDevelopmentCard(theBoard.currentPlayer);
                        devC.setPlayable(false);
                        theBoard.currentPlayer.giveDevelopmentCard(devC);
                        Board.TheBank.takePayment(theBoard.currentPlayer, Bank.DEV_CARD_COST);
                        theBoard.addEventText(UserMessages.PlayerPurchasedADevCard(theBoard.currentPlayer));

                        theBoard.checkForWinner();
                    } catch (BuildError be)
                    {
                        theBoard.addEventText(be.Message);
                    }
                }
                else if (sender is DevelopmentCard)
                {
                    DevelopmentCard card = (DevelopmentCard)sender;
                    if (card.isPlayable())
                    {
                        switch (card.getType())
                        {
                        case DevelopmentCard.DevCardType.Road:
                            //Player is allowed to place two roads for no cost
                            RoadBuildingEvt evt = new RoadBuildingEvt();
                            evt.beginExecution(theBoard, this);
                            disableEventObjects();
                            //Remove this card from the player's hand.
                            theBoard.currentPlayer.takeDevelopmentCard(card.getType());
                            break;

                        case DevelopmentCard.DevCardType.Plenty:
                            //Player is allowed to take any two resources from the bank
                            YearOfPlentyEvt yr = new YearOfPlentyEvt();
                            yr.beginExecution(theBoard, this);
                            disableEventObjects();
                            //Remove this card from the player's hand. They DO NOT go back to the bank
                            theBoard.currentPlayer.takeDevelopmentCard(card.getType());
                            break;

                        case DevelopmentCard.DevCardType.Knight:
                            //Launch the thief event
                            if (!card.used)
                            {
                                ThiefEvt thevt = new ThiefEvt();
                                thevt.beginExecution(theBoard, this);
                                disableEventObjects();
                                card.used = true;
                                theBoard.checkForWinner();
                            }
                            break;

                        case DevelopmentCard.DevCardType.Monopoly:
                            //Player names a resource, all players give this player that resource they carry
                            MonopolyEvt monEvt = new MonopolyEvt();
                            monEvt.beginExecution(theBoard, this);
                            disableEventObjects();
                            //Remove this card from the player's hand. They DO NOT go back to the bank
                            theBoard.currentPlayer.takeDevelopmentCard(card.getType());
                            break;
                        }
                    }
                    else
                    {
                        if (card.getType() != DevelopmentCard.DevCardType.Victory)
                        {
                            theBoard.addEventText("You must wait until the next turn to play that card.");
                        }
                    }
                }
                else if (sender is Harbor)
                {
                    Harbor hb = (Harbor)sender;
                    if (hb.playerHasValidSettlement(theBoard.currentPlayer))
                    {
                        if (TradeWindow.canPlayerTradeWithHarbor(hb, theBoard.currentPlayer))
                        {
                            disableEventObjects();
                            tradeWindow = new TradeWindow();
                            tradeWindow.loadHarborTrade(hb, theBoard.currentPlayer);
                            tradeWindow.Closing += onTradeEnded;
                            currentState         = State.Trade;
                            tradeWindow.Show();
                        }
                        else
                        {
                            theBoard.addEventText(BuildError.NOT_ENOUGH_RESOURCES);
                        }
                    }
                    else
                    {
                        theBoard.addEventText(UserMessages.PlayerDoesNotHaveAdjascentSettlement);
                    }
                }
                else if (sender is TradeProposition)
                {
                    var proposition = (TradeProposition)sender;
                    Board.TheBank.tradeWithBank(
                        theBoard.currentPlayer,
                        proposition,
                        theBoard.getPlayerBankCosts(theBoard.currentPlayer)
                        );
                    theBoard.addEventText($"{theBoard.currentPlayer.getName()} traded {proposition.selledResource} for {proposition.boughtResource}");
                }
                break;

            case State.Trade:
                //Should not be able to reach this statement.
                break;
            }
            //if (theBoard.currentPlayer.isAI)
            //{
            //    var move = theBoard.currentPlayer.agent.makeMove(theBoard.getBoardState());
            //    executeUpdate(move, null);
            //}
        }