예제 #1
0
    // Runs loop to check for valid user input. Checks for passed in valid answers and runs passed in functions if user inputs valid answer
    public static void ValidateInput(string prompt, string option1, MyFunction f1, string option2 = null, MyFunction f2 = null, string option3 = null, MyFunction f3 = null)
    {
        bool invalidInput = true;

        while (invalidInput)
        {
            RollingConsoleWrite(prompt);
            string userChoice = Console.ReadLine();
            if (userChoice == option1)
            {
                invalidInput = false;
                if (option1 == "restart")
                {
                    bread.ClearOrder();
                    pastries.ClearOrder();
                }
                f1();
            }
            else if (userChoice == option2 && option2 != null && f2 != null)
            {
                invalidInput = false;
                f2();
            }
            else if (userChoice == option3 && option3 != null && f3 != null)
            {
                invalidInput = false;
                f3();
            }
            else if (userChoice == "quit")
            {
                RollingConsoleWrite("Goodbye!");
                Environment.Exit(0);
            }
            else
            {
                RollingConsoleWrite("That was not a valid command!");
                Thread.Sleep(1000);
                Console.Clear();
            }
        }
    }