private void acceptClickToBank(object sender, EventArgs e)
        {
            //Tabulate calculate and complete the transactions!

            foreach (ResourceSelector select in playerResourceSelectors)
            {
                //Give bank this resource
                for (int i = 0; i < select.getCount(); i++)
                {
                    ResourceCard rc = initiatingPlayer.takeResource(select.type);
                    Board.TheBank.putResourceCard(rc);
                }
            }

            foreach (ResourceSelector select in otherResourceSelectors)
            {
                for (int i = 0; i < select.getCount(); i++)
                {
                    initiatingPlayer.giveResource(Board.TheBank.giveOutResource(select.type));
                }
            }

            //We are done.
            this.Close();
        }
        private void acceptClickPlayerToPlayer(object sender, EventArgs e)
        {
            int pCount = 0;

            foreach (ResourceSelector select in playerResourceSelectors)
            {
                //Give bank this resource
                pCount += select.getCount();
            }
            int oCount = 0;

            foreach (ResourceSelector select in otherResourceSelectors)
            {
                oCount += select.getCount();
            }

            if (!(pCount > 0 && oCount > 0))
            {
                MessageBox.Show("Both players must select at least one resource to continue.");
                return;
            }

            //Tabulate calculate and complete the transactions!

            foreach (ResourceSelector select in playerResourceSelectors)
            {
                //Give bank this resource
                for (int i = 0; i < select.getCount(); i++)
                {
                    //Give the other player this resource.
                    otherPlayer.giveResource(initiatingPlayer.takeResource(select.type));
                }
            }

            foreach (ResourceSelector select in otherResourceSelectors)
            {
                for (int i = 0; i < select.getCount(); i++)
                {
                    //Give the current player this resource.
                    initiatingPlayer.giveResource(otherPlayer.takeResource(select.type));
                }
            }

            //We are done.
            otherPlayer.Current = false;
            this.Close();
        }
예제 #3
0
        public bool tradeWithBank(Player player, TradeProposition proposition, IDictionary <Board.ResourceType, int> paymentCosts)
        {
            var selledResourceAmount = proposition.boughtResourceAmount * paymentCosts[proposition.selledResource];

            if (!canGiveOutResource(proposition.boughtResource, proposition.boughtResourceAmount) ||
                player.getResourceCount(proposition.selledResource) < selledResourceAmount)
            {
                return(false);
            }

            //Give bank this resource
            for (int i = 0; i < selledResourceAmount; i++)
            {
                ResourceCard rc = player.takeResource(proposition.selledResource);
                Board.TheBank.putResourceCard(rc);
            }

            //Get cards
            for (int i = 0; i < proposition.boughtResourceAmount; i++)
            {
                player.giveResource(Board.TheBank.giveOutResource(proposition.boughtResource));
            }
            return(true);
        }