Exemplo n.º 1
0
        public Money PriceOf(Item[] items, Shop shop)
        {
            Money money = new Money();
            for(int i = 0; i < items.Length; ++i)
            {
                money.Amount += shop.PriceOf(items[i]).Amount;
            }

            return money;
        }
Exemplo n.º 2
0
        // TOOD
        public void SellToShop(Shop shop, Player player, Item[] itemsToSell)
        {
            for(int i = 0; i < itemsToSell.Length; ++i)
            {
                Item item = itemsToSell[i];

                player.Money.Amount += shop.PriceOf(item).Amount;
                player.Inventory.Remove(item);

                shop.Add(item);
            }
        }
Exemplo n.º 3
0
        public void BuyFromShop(Shop shop, Player player, Item[] itemsToBuy)
        {
            Money price = PriceOf(itemsToBuy, shop);

            if (player.Money.Amount < price.Amount)
            {
                throw new Exception("You only have: " + player.Money.ToString() + ", the items you wish to buy cost: " + PriceOf(itemsToBuy, shop).ToString());
            }

            if (!player.Inventory.CanHold(itemsToBuy))
            {
                throw new Exception("You cannot hold the items that you wish to purchase!");
            }

            foreach (Item item in itemsToBuy)
            {
                Money priceOfItem = shop.PriceOf(item);

                player.Money.Amount -= priceOfItem.Amount;
                player.Inventory.Add(item);

                shop.Remove(item);
            }
        }