static public void CollectInput(Farm farm)
        {
            int response = StandardMessages.ShowMenu(_options, "Choose what facility to create...");

            if (response == 0)
            {
                return;                 // Going back...
            }
            else
            {
                IFacility newFacility  = GetNewFacility(response);
                string    facilityType = _options[response - 1];

                newFacility.Name = GetName(facilityType);

                farm.AddFacility(newFacility);

                Console.WriteLine($"Successfully added new {facilityType}: {newFacility.Name}");
            }
        }
示例#2
0
        public static void CollectInput(Farm farm)
        {
            Console.WriteLine(@"1. Grazing field");
            Console.WriteLine(@"2. Plowed field");
            Console.WriteLine(@"3. Natural field");
            Console.WriteLine(@"4. Duck House");
            Console.WriteLine(@"5. Chicken House");

            Console.WriteLine();
            Console.WriteLine("Choose what you want to create");

            Console.Write("> ");

            int option = 0;

            while (option == 0)
            {
                try
                {
                    option = Int32.Parse(Console.ReadLine());

                    switch (option)
                    {
                    case 1:
                        farm.AddFacility(new GrazingField());

                        Console.WriteLine("You made a new Grazing Field");
                        returnStatement();

                        break;

                    case 2:
                        farm.AddFacility(new PlowedField());
                        Console.WriteLine("You made a new Plowed Field");
                        returnStatement();

                        break;

                    case 3:
                        farm.AddFacility(new NaturalField());
                        Console.WriteLine("You made a new Natural Field");
                        returnStatement();
                        break;

                    case 4:
                        farm.AddFacility(new DuckHouse());
                        Console.WriteLine("A new Duck House has been built.");
                        returnStatement();
                        break;

                    case 5:
                        farm.AddFacility(new ChickenHouse());
                        Console.WriteLine("A new Chicken House has been built.");
                        returnStatement();
                        break;

                    default:
                        Console.WriteLine("Invalid selection. Hit Enter to return to the main menu.");
                        Console.Read();
                        break;
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Please select a valid number from above.");
                    Console.Write(" >");
                }
            }
        }