Ejemplo n.º 1
0
    public void Start()
    {
        Client client = new Client(howMuch);
        Terminal terminal = new Terminal();

        while (true)
        {
            Console.Clear();
            Console.WriteLine("1. Засунуть деньги в автомат   ");
            Console.WriteLine("2. Зайти в каталог продуктов   ");
            Console.WriteLine("3. Вытащить деньги из автомата ");
            Console.WriteLine("4. Завершение программы        ");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(client.ShowStatus());
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine("Нажмите цифру для выбора опции:");

            switch (Console.ReadKey().KeyChar)
            {
                case '1':
                    {
                        int money=0;
                        bool canBeChanged=false;
                        while (true)
                        {
                            Console.Clear();
                            Console.WriteLine("У вас монет по рублю: {0}, По два {1}, По пять: {2}, По десять: {3} | Всего {4}р.",
                                                                    client.one, client.two, client.five, client.ten, client.total);
                            Console.WriteLine("В терминале по рублю: {0}, По два {1}, По пять: {2}, По десять: {3} | Всего {4}р.",
                                                                    terminal.one, terminal.two, terminal.five, terminal.ten, terminal.total);
                            Console.WriteLine("Внесено всего : {0}р.", client.deposit);
                            if (client.total <= 0)
                            {
                                Console.WriteLine("К сожалению у вас закончились деньги, нажмите любую клавишу для выхода в меню.");
                                Console.ReadKey();
                                break;
                            }
                            Console.WriteLine("Вы можете внести деньги в терминал по рублю, два, пять или десять. Для этого введите число и нажмите Enter. Для выхода в меню введите -1 и нажмите Enter");
                            bool safeinput = int.TryParse(Console.ReadLine(), out money);
                            if (money == -1) break;
                            canBeChanged = client.DecreaseMoney(money);
                            client.Changedeposit(money, canBeChanged);
                            terminal.IncreaseMoney(money, canBeChanged);
                        }
                    }
                    break;
                case '2':
                    {
                        char? ch = null;
                        while (true)
                        {
                            Console.Clear();
                            Console.WriteLine("\n Товар     Цена Кол-во");
                            Console.WriteLine("---------------------");
                            Console.WriteLine("1.{0}   {1}   {2}", terminal.productname1, terminal.productcost1, terminal.productamount1);
                            Console.WriteLine("2.{0} {1}   {2}", terminal.productname2, terminal.productcost2, terminal.productamount2);
                            Console.WriteLine("3.{0}    {1}   {2}", terminal.productname3, terminal.productcost3, terminal.productamount3);
                            Console.WriteLine("Чтобы купить товар, нажмите цифру-идентификатор его порядка 1,2 или 3");
                            Console.WriteLine("Для выхода в главное меню нажмите клавишу 0");
                            Console.WriteLine("Вы внесли: " + client.deposit);
                            ch = Console.ReadKey().KeyChar;
                            if (ch == '0') break;
                            switch (ch)
                            {
                                case '1':
                                    {
                                        if (terminal.productamount1 <= 0) Console.WriteLine("У автомата пункт меню с {0} закончился ", terminal.productname1);
                                        else
                                            if (client.deposit - terminal.productcost1 < 0)
                                            {
                                                Console.WriteLine("Внесенной суммы не хватает для покупки " + terminal.productname1);
                                            }
                                            else
                                            {
                                                client.DecreaseDeposit(terminal.productcost1);
                                                terminal.DecreaseProductAmount(1);
                                                Console.WriteLine("Ву-ху, вы купили: " + terminal.productname1);
                                            }
                                    }
                                    break;
                                case '2':
                                    {
                                        if (terminal.productamount2 <= 0) Console.WriteLine("У автомата пункт меню с {0} закончился ", terminal.productname2);
                                        else
                                            if (client.deposit - terminal.productcost2 < 0)
                                            {
                                                Console.WriteLine("Внесенной суммы не хватает для покупки " + terminal.productname2);
                                            }
                                            else
                                            {
                                                client.DecreaseDeposit(terminal.productcost2);
                                                terminal.DecreaseProductAmount(2);
                                                Console.WriteLine("Ву-ху, вы купили: " + terminal.productname2);
                                            }
                                    }
                                    break;
                                case '3':
                                    {
                                        if (terminal.productamount3 <= 0) Console.WriteLine("У автомата пункт меню с {0} закончился ", terminal.productname3);
                                        else
                                            if (client.deposit - terminal.productcost3 < 0)
                                            {
                                                Console.WriteLine("Внесенной суммы не хватает для покупки " + terminal.productname3);
                                            }
                                            else
                                            {
                                                client.DecreaseDeposit(terminal.productcost3);
                                                terminal.DecreaseProductAmount(3);
                                                Console.WriteLine("Ву-ху, вы купили: " + terminal.productname3);
                                            }
                                    }
                                    break;
                            }
                            Console.ReadKey();
                        }
                    }
                    break;
                case '3':
                    {
                        while (true)
                        {
                            bool canBeChanged = false;
                            Console.Clear();
                            Console.WriteLine("У вас монет по рублю: {0}, По два {1}, По пять: {2}, По десять: {3} | Всего {4}р.",
                                                                    client.one, client.two, client.five, client.ten, client.total);
                            Console.WriteLine("В терминале по рублю: {0}, По два {1}, По пять: {2}, По десять: {3} | Всего {4}р.",
                                                                    terminal.one, terminal.two, terminal.five, terminal.ten, terminal.total);
                            Console.WriteLine("Внесено всего : {0}р.", client.deposit);
                            Console.WriteLine("========================");
                            Console.WriteLine("Нажмите на клавишу 1 для выдачи сдачи");
                            Console.WriteLine("Для выхода нажмите 0");
                            char ch = Console.ReadKey().KeyChar;
                            if (ch == '0') break;
                            else if (ch == '1')
                            {
                                if (client.deposit <= 0)
                                {
                                    Console.WriteLine("В автомате нет денег для сдачи, нажмите любую клавижу для продолжения");
                                    Console.ReadKey();
                                }

                                else
                                {
                                    while (client.deposit > 0)
                                    {
                                        if (terminal.ten > 0 && client.deposit >= 10)
                                        {
                                            canBeChanged = terminal.DecreaseMoney(10);
                                            client.IncreaseMoney(10, canBeChanged);
                                            client.DecreaseDeposit(10);
                                        }
                                        else if (terminal.five > 0 && client.deposit>=5)
                                        {
                                            canBeChanged = terminal.DecreaseMoney(5);
                                            client.IncreaseMoney(5, canBeChanged);
                                            client.DecreaseDeposit(5);
                                        }
                                        else if (terminal.two > 0 && client.deposit >= 2)
                                        {
                                            canBeChanged = terminal.DecreaseMoney(2);
                                            client.IncreaseMoney(2, canBeChanged);
                                            client.DecreaseDeposit(2);
                                        }
                                        else if (terminal.one > 0 && client.deposit >= 1)
                                        {
                                            canBeChanged = terminal.DecreaseMoney(1);
                                            client.IncreaseMoney(1, canBeChanged);
                                            client.DecreaseDeposit(1);
                                        }
                                    }
                                }
                            }

                        }
                    }
                    break;
                case '4': Environment.Exit(0);
                    break;
                default: Console.WriteLine("\n=============Нажмите корректную цифру от 1 до 4============\n"); ;
                    break;
            }
        }
    }