Пример #1
0
        public void ShowMainUi()
        {
            if (!Console.IsOutputRedirected)
            {
                Console.Clear();
            }
            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("______________________VENDING MACHINE_______________________");
            Console.WriteLine("| (I) Insert Coin                               (R) Refund |");
            Console.WriteLine("|                                                          |");
            Console.WriteLine("| (S) Soda: 1.00       (H) Chips: .50       (C) Candy: .65 |");
            Console.WriteLine("|                                                          |");
            Console.WriteLine("| (T) Take Item (" + _foodSlot.GetListOfItemsInSlot().Count + " items)        (N) Coin Return (" + _coinReturn.CheckReturn().Count + " items) |");
            Console.WriteLine("____________________________________________________________");
            Console.WriteLine("");

            if (_coinValidator.GetCurrentTransactionTotal() > 0)
            {
                _display.CurrentTotalMessage(_coinValidator.GetCurrentTransactionTotal());
            }
            else if (!_coinBank.CanMakeChange())
            {
                _display.ExactChangeMessage();
            }
            else
            {
                _display.InsertCoinMessage();
            }

            Console.WriteLine("Enter the letter of the item you wish to access");
            Console.WriteLine("-OR-");
            Console.WriteLine("Enter 'Display' at any time to check the display, or 'E' to Exit.");

            _showMainUiWasCalled = true;
            _entry = _console.ReadLine();

            switch (_entry)
            {
            case ("I"):
                ShowInsertCoinUi();
                break;

            case ("R"):
                _coinSlot.GiveRefund();
                ShowCoinReturnUi();
                break;

            case ("S"):
            case ("H"):
            case ("C"):
                if (_foodDispenser.Dispense(_entry, _coinValidator, _coinBank, _foodSlot, _display))
                {
                    Console.WriteLine("You hear a *thunk* as an item lands in the Food Slot.");
                    ShowFoodSlotUi();
                }
                else
                {
                    Console.WriteLine("Nothing happens.");
                    ShowRedirectUi();
                }
                break;

            case ("T"):
                ShowFoodSlotUi();
                break;

            case ("N"):
                ShowCoinReturnUi();
                break;

            case ("DISPLAY"):
                ShowDisplayUi();
                break;

            case ("E"):
                break;

            default:
                if (!Console.IsOutputRedirected)
                {
                    InvalidInput();
                }
                break;
            }
        }