7

Im trying to code a simple text adventure. when I started to code the directions a user can head in I realized the user could put in "north east", "south west" etc so I thought I should make cases for them.

my problem is case5 "north east" does not run when I input "north east" into the command line.

class Branches

    {
        static void main(string[] args)
        {
            Branch2();
        }

        public static void Branch2()
        {
            Console.WriteLine("");
            Console.WriteLine("(North ,East ,South ,West)");
            string input = Console.ReadLine();
            bool case1 = input.Contains("north");
            bool case2 = input.Contains("east");
            bool case3 = input.Contains("south");
            bool case4 = input.Contains("west");
            bool case5 = input.Contains("north") && input.Contains("east");

            //Console.ReadLine(); 
            int CaseId;
            if (case1)
                CaseId = 1;
            else if (case2)
                CaseId = 2;
            else if (case3)
                CaseId = 3;
            else if (case4)
                CaseId = 4;
            else if (case5)
                CaseId = 5;

            else
                CaseId = 0;

            switch (CaseId)
            {
                case 1:
                    Console.WriteLine("");
                    Console.WriteLine("you head north");
                    break;

                case 2:
                    Console.WriteLine("");
                    Console.WriteLine("you head east");
                    break;

                case 3:
                    Console.WriteLine("");
                    Console.WriteLine("you head south");
                    break;

                case 4:
                    Console.WriteLine("");
                    Console.WriteLine("you head west");
                    break;

                case 5:
                    Console.WriteLine("");
                    Console.WriteLine("you head north east");
                    break;

                default:
                    Console.WriteLine("enter a valid direction");
                    break;


            }
        }
    }

}
4

4 に答える 4