/*
         * The following are all the events that drives each of the individual trade window events.
         *
         */

        private void ptpClickResourceSelectorPlayer(object sender, EventArgs e)
        {
            //Player offer
            if (sender is ResourceSelector)
            {
                ResourceSelector resSelect = (ResourceSelector)sender;
                int count = resSelect.getCount() + 1;
                //Check if the current player has the required number of resources
                if (initiatingPlayer.getResourceCount(resSelect.type) >= count)
                {
                    resSelect.setCount(count);
                    resSelect.setSelected(true);
                }
                else
                {
                    MessageBox.Show(BuildError.NOT_ENOUGH_RESOURCES);
                }
            }
        }
 public static bool canPlayerTradeWithHarbor(Harbor hb, Player pl)
 {
     foreach (Board.ResourceType rt in Enum.GetValues(typeof(Board.ResourceType)))
     {
         //Get the player's current resource counts.
         int count = pl.getResourceCount(rt);
         if (count >= hb.getRequiredResourceCount())
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #3
0
        public static bool hasPayment(Player p, Board.ResourceType[] paymentList)
        {
            int[] resourceList = new int[6];
            bool  satisfied    = true;

            foreach (Board.ResourceType res in paymentList)
            {
                resourceList[(int)res]++;
            }
            for (int i = 0; i < 6; i++)
            {
                if (!(p.getResourceCount((Board.ResourceType)i) >= resourceList[i]))
                {
                    satisfied = false;
                }
            }
            return(satisfied);
        }
Beispiel #4
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);
        }