C#一直问问题,直到按下按钮

时间:2019-05-04 22:51:49

标签: c# while-loop

我使用了一个do和while使循环继续进行。无论发生什么事情,我都希望问题再次出现。

我要发生的事情是根据用户想要的选项要求用户按下按钮。他们与该部分互动之后,我希望问题再次出现,以便他们选择其他选项。

我似乎无法使问题重复。

namespace Magic8Ball_Console
{
    class Program
    {
        public static string userAnswer = "";

        static void Main(string[] args)
        {
            Console.WriteLine("Main program!");
            Console.WriteLine("Welcome to the Magic 8 Ball");
            Console.WriteLine("What would you like to do?");
            Console.WriteLine("(S)hake the Ball");
            Console.WriteLine("(A)sk a Question");
            Console.WriteLine("(G)et the Answer");
            Console.WriteLine("(E)xit the Game");
            Magic8Ball_Logic.Magic8Ball ball = new Magic8Ball_Logic.Magic8Ball();
            string input = Console.ReadLine().ToUpper();

                if (input == "S")
                {
                    if (userAnswer != null)
                    {
                        Console.WriteLine("Searching the Mystic Realms(RAM) for the answer");
                        Console.ReadLine();
                    }
                    else
                    {
                        //Call Method Shake()
                        ball.Shake();
                }
                }
                else if (input == "A")
                {
                    userAnswer = Console.ReadLine();
                }
                else if (input == "G")
                {
                    if (userAnswer != null)
                    {
                        Console.WriteLine("Please Enter A Question Before Asking For An Answer.");
                        Console.ReadLine();
                    }
                    else
                    {
                        //Call Method GetAnswer()
                        ball.GetAnswer();
                }
                }
        }
    }
}

0 个答案:

没有答案