public void Dispense(Dispense dispense)
        {
            var displayDenimonations = new DisplayDenominations();

            CurrencyTypes currencyType = new CurrencyTypes();
            var           denomination = currencyType.FiveHundreds;

            if (dispense.Amount >= denomination)
            {
                var count     = dispense.Amount / denomination;
                var remainder = dispense.Amount % denomination;
                if (count != 0)
                {
                    displayDenimonations.Display(denomination, count);
                }
                if (remainder > 0)
                {
                    _dispenser.Dispense(new Dispense {
                        Amount = remainder
                    });
                }
            }
            else if (_dispenser != null)
            {
                _dispenser.Dispense(dispense);
            }
        }
예제 #2
0
        public int Dispense(int amount)
        {
            if (amount < _bill.Denomination)
            {
                return(_next.Dispense(amount));
            }

            int remaining = _bill.Withdral(amount);

            if (remaining != 0)
            {
                return(_next.Dispense(remaining));
            }

            return(remaining);
        }
예제 #3
0
        private IPlanet GeneratePlanet(IEnumerable <IPlanet> planets)
        {
            var maxIterations = 100;
            var counter       = 0;

            while (counter++ < maxIterations)
            {
                if (_positionsGenerator.TryGeneratePosition(planets, out var position) == false)
                {
                    continue;
                }

                if (_sizesGenerator.TryGenerateRadius(_positionsGenerator.lastMinDistanceToObjectsBorders, out var radius) == false)
                {
                    continue;
                }

                return(GeneratePlanet(position, radius, _spriteDispenser.Dispense()));
            }

            return(default);
예제 #4
0
        public void Dispense(IEnumerable <OrderItem> items)
        {
            IEnumerable <DispenseCommand> dispensingChain = _strategy.BuildDispensingChain(items);

            foreach (DispenseCommand command in dispensingChain)
            {
                IDispenser _dispenser = _dispensers.SingleOrDefault(x => x.Id == command.Address.VendingMachineID);

                if (_dispenser == null)
                {
                    OnFailed?.Invoke(this, new DispenseFailEventArgs {
                        address = command.Address.Address, message = "Unable to detect the machine"
                    });
                }

                if (_dispenser.Dispense(command.Address, command.Quantity))
                {
                    OnDispensing?.Invoke(this, new DispenseEventArgs {
                        address = command.Address.Address
                    });
                }
            }
        }
 public IDrinkable GetDrink()
 {
     return(_dispenser.Dispense());
 }