Beispiel #1
0
        private void BuyItem(CommercialBuilding building, ICommercialItem item, Button button)
        {
            try
            {
                int currentCash = this.ninja.Cash;
                building.Sell(item, ninja);
                if (currentCash == this.ninja.Cash)
                {
                    MessageBox.Show("You rich the maximum of items that you can hold (30 items)!");
                }
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message);
            }

            button.PerformClick();
        }
        public void Sell(ICommercialItem commercialItem, IHero hero)
        {
            // If ninja have enough money to pay, he pays
            if (hero.PayCash(commercialItem.Price))
            {
                // If ninja accepts the item he takes it
                if (hero.GetItem(commercialItem))
                {
                    int index = this.goods.IndexOf(commercialItem);
                    this.goods.RemoveAt(index);

                    var itemRecharge = commercialItem.Clone();
                    this.goods.Insert(index, itemRecharge as ICommercialItem);
                    TurnOver += commercialItem.Price;
                }
                else
                {
                    // Return money
                    hero.GetCash(commercialItem.Price);
                }
            }
        }
        public void Sell(ICommercialItem commercialItem, IHero hero)
        {
            // If ninja have enough money to pay, he pays
            if (hero.PayCash(commercialItem.Price))
            {
                // If ninja accepts the item he takes it
                if (hero.GetItem(commercialItem))
                {
                    int index = this.goods.IndexOf(commercialItem);
                    this.goods.RemoveAt(index);

                    var itemRecharge = commercialItem.Clone();
                    this.goods.Insert(index, itemRecharge as ICommercialItem);
                    TurnOver += commercialItem.Price;
                }
                else
                {
                    // Return money
                    hero.GetCash(commercialItem.Price);
                }
            }
        }
        private void BuyItem(CommercialBuilding building, ICommercialItem item, Button button)
        {
            try
            {
                int currentCash = this.ninja.Cash;
                building.Sell(item, ninja);
                if (currentCash == this.ninja.Cash)
                {
                    MessageBox.Show("You rich the maximum of items that you can hold (30 items)!");
                }
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message);
            }

            button.PerformClick();
        }