コード例 #1
0
        public void Buy(BuildableObject rideOrShop, Wallet fromWallet, ParkInventory toInventory)
        {
            if (fromWallet.Balance < rideOrShop.Cost)
            {
                throw new ArgumentException("Wallet does not have enough money! Check balance in the UI before calling this method.");
            }

            if (toInventory.Contains(rideOrShop))
            {
                throw new ArgumentException("Inventory already contains this item! Check if player owns the item before calling this method.");
            }

            if (rideOrShop is Ride)
            {
                Ride ride = rideOrShop as Ride;

                toInventory.Rides.Add(ride);
                purchasedRides.Add(ride);
            }
            else if (rideOrShop is Shop)
            {
                Shop shop = rideOrShop as Shop;

                toInventory.Shops.Add(shop);
                purchasedShops.Add(shop);
            }

            // Always deduct the money
            fromWallet.SubtractFromBalance(rideOrShop.Cost, "Bought " + rideOrShop.Name);
        }
コード例 #2
0
        // Checks whether we already have a ride
        public bool Contains(BuildableObject ride)
        {
            foreach (Ride inventoryRide in Rides)
            {
                if (ride == inventoryRide)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
        internal void Add(BuildableObject buildableObject)
        {
            buildableObject.ParentInventory = this;

            if (buildableObject is Shop)
            {
                Shops.Add(buildableObject as Shop);
            }
            else if (buildableObject is Ride)
            {
                Rides.Add(buildableObject as Ride);
            }
            else
            {
                throw new ArgumentException("Tried to add something other than shop or ride to inventory!");
            }
        }