Beispiel #1
0
        public int InsertCoin(MachineStash MachineStash, int  pocketMoney)
        {
            PrintService.PrintInsertMenu(pocketMoney, MachineStash);

            char selectedMenu = 'a';
            while (selectedMenu != '0')
            {
                //Read key for menu
                selectedMenu = Console.ReadKey().KeyChar;

                //Return key symbol as index number - 1
                var idx = (int)selectedMenu - 49;

                if (idx>=0 && idx < MachineStash.coins.Count)
                {

                    if (pocketMoney >= MachineStash.coins.Keys.ElementAt(idx))
                    {
                        MachineStash.IncertCoin(MachineStash.coins.Keys.ElementAt(idx));
                        pocketMoney -= MachineStash.coins.Keys.ElementAt(idx);
                        PrintService.PrintInsertMenu(pocketMoney, MachineStash);
                    }
                    else
                    {
                        PrintService.PrintInsertMenu(pocketMoney, MachineStash);
                        PrintService.PrintError("Недостаточно денег");
                    }
                }
                else
                {
                    break;
                }
            }
            return pocketMoney;
        }
Beispiel #2
0
        public void PrintAllCoinsInside(MachineStash MachineStash)
        {
            Console.WriteLine("В автомате:");
            foreach (KeyValuePair<int, int> coin in MachineStash.coins)
            {
                Console.WriteLine("  " + coin.Value + " x "+ coin.Key + " руб");
            }

            Console.WriteLine("Всего: " + MachineStash.GiveAllMoneyInside() + " руб\n");
        }
Beispiel #3
0
        public void PrintItemMenu(MachineStash MachineStash)
        {
            Console.Clear();

            Console.WriteLine("Выбрать позицию:    " + "Балланс: " + MachineStash.balance + "\n");
            var idx = 1;
            foreach (Item item in MachineStash.items.Values)
            {
                Console.WriteLine("  " + idx + ". " + item.title + " - " + item.price + " руб  —  "+ MachineStash.stock[MachineStash.stock.Keys.ElementAt(idx - 1)] + " шт.");
                idx++;
            }
            Console.WriteLine("  Любая клавиша —  Отмена\n");
        }
Beispiel #4
0
        public void PrintInsertMenu(int pocketMoney, MachineStash MachineStash)
        {
            Console.Clear();

            Console.WriteLine("Положить монетку:    " + "Балланс: " + MachineStash.balance + "\n");
            Console.WriteLine("  1. - 1  руб");
            Console.WriteLine("  2. - 2  руб");
            Console.WriteLine("  3. - 5  руб");
            Console.WriteLine("  4. - 10 руб");
            Console.WriteLine("  Любая клавиша — отмена\n");

            Console.WriteLine("В кошельке: " + pocketMoney + " руб\n");
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var Interactions = new Interactions();
            var PrintService = new PrintService();
            var MashineStash = new MachineStash();

            int pocketMoney = 150;

            Console.CursorVisible = false;

            PrintService.PrintMainMenu(pocketMoney, MashineStash);
            char selectedMenu = 'a';
            while (selectedMenu != '0')
            {
                //Read key for menu
                selectedMenu = Console.ReadKey().KeyChar;

                switch (selectedMenu)
                {
                    case ('1'):
                        {
                            //Insert money and repaint screen after
                            pocketMoney = Interactions.InsertCoin(MashineStash, pocketMoney);
                            PrintService.PrintMainMenu(pocketMoney, MashineStash);
                            break;
                        }
                    case ('2'):
                        {
                            //Buy items and repaint screen after
                            Interactions.ChooseMenuItem(MashineStash);
                            PrintService.PrintMainMenu(pocketMoney, MashineStash);
                            break;
                        }
                    case ('3'):
                        {
                            //Receive money and show what
                            PrintService.PrintMainMenu(pocketMoney, MashineStash);
                            pocketMoney += Interactions.ReceiveMoney(pocketMoney, MashineStash);
                            break;
                        }
                    default:
                        {
                            //Don't show press key
                            PrintService.PrintMainMenu(pocketMoney, MashineStash);
                            break;
                        }
                }
            }
        }
Beispiel #6
0
        public void PrintMainMenu(int pocketMoney, MachineStash MachineStash)
        {
            Console.Clear();

            Console.WriteLine("Автомат печенек      " + "Балланс: " + MachineStash.balance + "\n");

            Console.WriteLine("Выберите номер пункта:");
            Console.WriteLine("  1. Внести деньги");
            Console.WriteLine("  2. Выбрать позицию");
            Console.WriteLine("  3. Вернуть сдачу");
            Console.WriteLine("  0. Выход\n");

            Console.WriteLine("В кошельке: " + pocketMoney + " руб\n");
            PrintAllCoinsInside(MachineStash);
        }
Beispiel #7
0
        /// <summary>
        /// Show menu of product selection
        /// </summary>
        /// <param name="MachineStash"></param>
        public void ChooseMenuItem(MachineStash MachineStash)
        {
            PrintService.PrintItemMenu(MachineStash);

            char selectedMenu = 'a';
            while (selectedMenu != '4')
            {
                //Read key for menu
                selectedMenu = Console.ReadKey().KeyChar;
                //Return key symbol as index number - 1
                var idx = (int)selectedMenu - 49;

                if (idx >= 0 && idx < MachineStash.items.Count)
                {
                    var selectedItem = MachineStash.items[MachineStash.items.Keys.ElementAt(idx)];
                    if (MachineStash.balance < selectedItem.price)
                    {
                        PrintService.PrintItemMenu(MachineStash);
                        PrintService.PrintError("Недостаточно денег");
                        continue;
                    }

                    if (MachineStash.stock[selectedItem.name] <= 0)
                    {
                        PrintService.PrintItemMenu(MachineStash);
                        PrintService.PrintError("Недостаточно товара");
                        continue;
                    }

                    //Correct your pocket and machine balance after buing
                    MachineStash.balance -= selectedItem.price;
                    --MachineStash.stock[selectedItem.name];
                    PrintService.PrintItemMenu(MachineStash);
                }
                else
                {
                    break;
                }
            }
        }
Beispiel #8
0
        public int ReceiveMoney(int pocketMoney, MachineStash MachineStash)
        {
            var coin = new int[4];
            int returnMoney = 0,
                balance = MachineStash.balance;

            if (MachineStash.balance == 0)
            {
                PrintService.PrintError("Нечего возвращать");
                return returnMoney;
            }

            //Begin from 10 coin
            for (int idx = 3; idx >= 0; idx--)
            {
                //How many max value coins can you receive
                coin[idx] = balance / MachineStash.coins.Keys.ElementAt(idx);
                //If machine has, it give all max value coin
                if (MachineStash.coins[MachineStash.coins.Keys.ElementAt(idx)] >= coin[idx])
                {
                    balance -= coin[idx] * MachineStash.coins.Keys.ElementAt(idx);
                    returnMoney += coin[idx] * MachineStash.coins.Keys.ElementAt(idx);
                    MachineStash.coins[MachineStash.coins.Keys.ElementAt(idx)] -= coin[idx];
                }
                //Give how many coins (max value) it has. (If 0 - give 0)
                else
                {
                    coin[idx] = MachineStash.coins[MachineStash.coins.Keys.ElementAt(idx)];
                    balance -= coin[idx] * MachineStash.coins.Keys.ElementAt(idx);
                    returnMoney += coin[idx] * MachineStash.coins.Keys.ElementAt(idx);
                    MachineStash.coins[MachineStash.coins.Keys.ElementAt(idx)] -= coin[idx];
                }
            }

            if (balance > 0)
            {
                PrintService.PrintError("Отсутствует сдача");
                return 0;
            }

            MachineStash.balance = balance;
            //Print refresh info
            PrintService.PrintMainMenu(pocketMoney + returnMoney, MachineStash);
            PrintService.ShowCoinsReceived(coin[0], coin[1], coin[2], coin[3]);
            return returnMoney;
        }