private static void StartMachine()
        {
            IConsole        console       = new VmGetInput();
            VmCoinValidator coinValidator = new VmCoinValidator();
            VmCoinReturn    coinReturn    = new VmCoinReturn();
            VmCoinSlot      coinSlot      = new VmCoinSlot(new List <string>(), coinReturn, coinValidator);
            VmFoodDispenser foodDispenser = new VmFoodDispenser();
            VmFoodSlot      foodSlot      = new VmFoodSlot();
            VmCoinBank      coinBank      = new VmCoinBank(new List <string>(), coinValidator, coinSlot, coinReturn);
            VmDisplay       display       = new VmDisplay(console);
            VmUi            mainUi        = new VmUi(coinSlot, coinValidator, coinReturn, foodDispenser, foodSlot, coinBank, console, display);

            coinBank.Restock();
            foodDispenser.Restock();
            mainUi.ShowMainUi();
        }
Exemple #2
0
 private void DispenseSoda(int currentTransactionTotal, VmCoinBank coinBank, VmFoodSlot foodSlot, string itemToDispense, VmDisplay display)
 {
     if (_soda.Count == 0)
     {
         display.SoldOutMessage();
     }
     else if (currentTransactionTotal < SODA_COST)
     {
         display.PriceMessage(SODA_COST);
     }
     else
     {
         _soda.Remove(SODA_STRING);
         coinBank.MakeChange(currentTransactionTotal - SODA_COST);
         foodSlot.AcceptFood("Soda");
     }
 }
Exemple #3
0
 private void DispenseCandy(int currentTransactionTotal, VmCoinBank coinBank, VmFoodSlot foodSlot, string itemToDispense, VmDisplay display)
 {
     if (_candy.Count == 0)
     {
         display.SoldOutMessage();
     }
     else if (currentTransactionTotal < CANDY_COST)
     {
         display.PriceMessage(SODA_COST);
     }
     else
     {
         _candy.Remove(CANDY_STRING);
         coinBank.MakeChange(currentTransactionTotal - CANDY_COST);
         foodSlot.AcceptFood("Candy");
     }
 }
Exemple #4
0
        public VmUi(VmCoinSlot coinSlot, VmCoinValidator coinValidator, VmCoinReturn coinReturn, VmFoodDispenser foodDispenser, VmFoodSlot foodSlot, VmCoinBank coinBank, IConsole console, VmDisplay display)
        {
            _coinSlot      = coinSlot;
            _coinValidator = coinValidator;
            _coinReturn    = coinReturn;
            _foodDispenser = foodDispenser;
            _foodSlot      = foodSlot;
            _coinBank      = coinBank;
            _console       = console;
            _display       = display;

            _showMainUiWasCalled       = false;
            _showInsertCoinUiWasCalled = false;
            _showDisplayUiWasCalled    = false;
            _showCoinReturnUiWasCalled = false;
            _showFoodSlotUiWasCalled   = false;
            _showRedirectUiWasCalled   = false;
        }
Exemple #5
0
        public bool Dispense(string itemToDispense, VmCoinValidator validator, VmCoinBank coinBank, VmFoodSlot foodSlot, VmDisplay display)
        {
            int currentTransactionTotal = validator.GetCurrentTransactionTotal();

            if (itemToDispense == SODA_STRING && _soda.Count == 0 || itemToDispense == CHIPS_STRING && _chips.Count == 0 ||
                itemToDispense == CANDY_STRING && _candy.Count == 0)
            {
                display.SoldOutMessage();
                return(false);
            }

            if (itemToDispense == SODA_STRING && currentTransactionTotal < SODA_COST)
            {
                display.PriceMessage(SODA_COST);
                return(false);
            }
            if (itemToDispense == CHIPS_STRING && currentTransactionTotal < CHIPS_COST)
            {
                display.PriceMessage(CHIPS_COST);
                return(false);
            }
            if (itemToDispense == CANDY_STRING && currentTransactionTotal < CANDY_COST)
            {
                display.PriceMessage(CANDY_COST);
                return(false);
            }

            switch (itemToDispense)
            {
            case SODA_STRING:
                DispenseSoda(currentTransactionTotal, coinBank, foodSlot, itemToDispense, display);
                display.ThankYouMessage();
                validator.CompleteTransaction();
                return(true);

            case CHIPS_STRING:
                DispenseChips(currentTransactionTotal, coinBank, foodSlot, itemToDispense, display);
                display.ThankYouMessage();
                validator.CompleteTransaction();
                return(true);

            case CANDY_STRING:
                DispenseCandy(currentTransactionTotal, coinBank, foodSlot, itemToDispense, display);
                display.ThankYouMessage();
                validator.CompleteTransaction();
                return(true);

            default:
                return(false);
            }
        }