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();
        }
Esempio n. 2
0
        public ResourceCard takeRandomResource()
        {
            ResourceCard rCard = null;

            if (resources.Count > 0)
            {
                int num = rand.Next(0, resources.Count);
                rCard = resources[num];
                resources.Remove(rCard);
            }
            else
            {
                return(null);
            }
            updateResourceDisplays();
            return(rCard);
        }
Esempio n. 3
0
        /**
         *  Gets a resource card witht the matching type from the player's
         *  deck. If no available card exists null is returned.
         */
        public ResourceCard takeResource(Board.ResourceType type)
        {
            ResourceCard rCard = null;

            foreach (ResourceCard res in resources)
            {
                if (res.getResourceType() == type)
                {
                    rCard = res;
                }
            }
            if (rCard != null)
            {
                resources.Remove(rCard);
            }
            updateResourceDisplays();
            return(rCard);
        }
Esempio n. 4
0
 public void distributeResource()
 {
     if (tileType != Board.ResourceType.Desert)
     {
         foreach (Settlement set in adjascentSettlements)
         {
             if (set.getOwningPlayer() != null)
             {
                 ResourceCard rc = Board.TheBank.giveOutResource(tileType);
                 if (rc != null)
                 {
                     set.getOwningPlayer().giveResource(rc);
                 }
                 else
                 {
                     MessageBox.Show("No more resources to give!");
                 }
             }
         }
     }
 }
Esempio n. 5
0
        /*
         *  Players can get this type of resource. If no resource is available, none is given.
         */
        public ResourceCard giveOutResource(Board.ResourceType type)
        {
            ResourceCard c = null;

            for (int i = 0; i < resources.Count; i++)
            {
                if (resources[i].getResourceType() == type)
                {
                    c = resources[i];
                    i = resources.Count;
                }
            }

            if (c != null)
            {
                resources.Remove(c);
            }
            else
            {
                //MessageBox.Show("There are no more resource cards in the deck.");
            }
            return(c);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
 public void putResourceCard(ResourceCard rc)
 {
     this.resources.Add(rc);
 }
Esempio n. 8
0
 public void giveResource(ResourceCard resCard)
 {
     this.resources.Add(resCard);
     updateResourceDisplays();
 }