public static void CollectInput(Farm farm, Chicken animal)
        {
            Console.Clear();

            List <ChickenCoop> openChickenCoops = new List <ChickenCoop>();

            List <ChickenCoop> sortedCoops = farm.ChickenCoop.Where(coop => (coop.Capacity - 1) >= coop.CurrentStock()).ToList();

            for (int i = 0; i < sortedCoops.Count; i++)
            {
                if ((sortedCoops[i].Capacity - 1) >=
                    sortedCoops[i].CurrentStock())
                {
                    openChickenCoops.Add(sortedCoops[i]);
                    Console.WriteLine($"{i + 1}. Chicken Coop (Current Stock: {sortedCoops[i].CurrentStock()})");

                    sortedCoops[i].ShowAnimalsByType();
                }
            }

            Console.WriteLine();

            if (openChickenCoops.Count > 0)
            {
                Console.WriteLine($"Place the animal where?");

                Console.Write("> ");
                try
                {
                    int choice = Int32.Parse(Console.ReadLine());
                    if (animal is Chicken)
                    {
                        try
                        {
                            sortedCoops[choice - 1].AddResource(animal);
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            Console.WriteLine("Invalid option. Please try again.");
                            Thread.Sleep(2000);
                            ChooseChickenCoop.CollectInput(farm, new Chicken());
                        }
                    }
                    else
                    {
                        Console.WriteLine("There are no matching facilities available. Please create one first.");
                        Thread.Sleep(2000);
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Invalid option. Please try again.");
                    Thread.Sleep(2000);
                    ChooseChickenCoop.CollectInput(farm, new Chicken());
                }
            }
        }
Exemple #2
0
        public static void CollectInput(Farm farm)
        {
            Console.WriteLine("1. Cow");
            Console.WriteLine("2. Ostrich");
            Console.WriteLine("3. Goat");
            Console.WriteLine("4. Pig");
            Console.WriteLine("5. Sheep");
            Console.WriteLine("6. Chicken");
            Console.WriteLine("7. Duck");



            Console.WriteLine();
            Console.WriteLine("What are you buying today?");

            Console.Write("> ");
            string choice = Console.ReadLine();

            switch (Int32.Parse(choice))
            {
            case 1:
                ChooseGrazingField.CollectInput(farm, new Cow());
                break;

            case 2:
                ChooseGrazingField.CollectInput(farm, new Ostrich());
                break;

            case 3:
                ChooseGrazingField.CollectInput(farm, new Pig());
                break;

            case 4:
                ChooseGrazingField.CollectInput(farm, new Goat());
                break;

            case 5:
                ChooseGrazingField.CollectInput(farm, new Sheep());
                break;

            case 6:
                ChooseChickenCoop.CollectInput(farm, new Chicken());
                break;

            case 7:
                ChooseDuckFarm.CollectInput(farm, new Duck());
                break;

            default:
                break;
            }
        }
        public static void CollectInput(Farm farm)
        {
            Console.WriteLine("1. Cow");
            Console.WriteLine("2. Ostrich");
            Console.WriteLine("3. Goat");
            Console.WriteLine("4. Sheep");
            Console.WriteLine("5. Pig");
            Console.WriteLine("6. Dragon");
            Console.WriteLine("7. Duck");
            Console.WriteLine("8. Chicken");
            Console.WriteLine();
            Console.WriteLine("What are you buying today?");

            Console.Write("> ");
            string input = Console.ReadLine();

            if (input != "" && int.TryParse(input, out int choice))
            {
                switch (choice)
                {
                case 1:
                    if (farm.GrazingFields.Count != 0)
                    {
                        ChooseGrazingField.CollectInput(farm, new Cow());
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n");
                        Console.WriteLine("There ain't no field for your cows!");
                        Console.WriteLine("\n\n");
                        Console.WriteLine("Press enter to continue");
                        Console.ReadLine();
                        break;
                    }

                case 2:
                    if (farm.GrazingFields.Count != 0)
                    {
                        ChooseGrazingField.CollectInput(farm, new Ostrich());
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n");
                        Console.WriteLine("There ain't no field for your ostrichesessss!");
                        Console.WriteLine("\n\n");
                        Console.WriteLine("Press enter to continue");
                        Console.ReadLine();
                        break;
                    }

                case 3:
                    if (farm.GrazingFields.Count != 0)
                    {
                        ChooseGrazingField.CollectInput(farm, new Goat());
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n");
                        Console.WriteLine("There ain't no field for your gorgeous goats!");
                        Console.WriteLine("\n\n");
                        Console.WriteLine("Press enter to continue");
                        Console.ReadLine();
                        break;
                    }

                case 4:
                    if (farm.GrazingFields.Count != 0)
                    {
                        ChooseGrazingField.CollectInput(farm, new Sheep());
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n");
                        Console.WriteLine("There ain't no field for your Shipes!");
                        Console.WriteLine("\n\n");
                        Console.WriteLine("Press enter to continue");
                        Console.ReadLine();
                        break;
                    }

                case 5:
                    if (farm.GrazingFields.Count != 0)
                    {
                        ChooseGrazingField.CollectInput(farm, new Pig());
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n");
                        Console.WriteLine("There ain't no field for your Pigs!");
                        Console.WriteLine("\n\n");
                        Console.WriteLine("Press enter to continue");
                        Console.ReadLine();
                        break;
                    }

                case 6:
                    if (farm.GrazingFields.Count != 0)
                    {
                        ChooseGrazingField.CollectInput(farm, new Dragon());
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n");
                        Console.WriteLine("There ain't no field for your Dragons!");
                        Console.WriteLine("\n\n");
                        Console.WriteLine("Press enter to continue");
                        Console.ReadLine();
                        break;
                    }

                case 7:
                    if (farm.DuckHouses.Count != 0)
                    {
                        ChooseDuckHouse.CollectInput(farm, new Duck());
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n");
                        Console.WriteLine("You ain't got no duck house!");
                        Console.WriteLine("\n\n");
                        Console.WriteLine("Press enter to continue");
                        Console.ReadLine();
                        break;
                    }

                case 8:
                    if (farm.ChickenCoops.Count != 0)
                    {
                        ChooseChickenCoop.CollectInput(farm, new Chicken());
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n");
                        Console.WriteLine("There ain't no field for your Chickens!");
                        Console.WriteLine("\n\n");
                        Console.WriteLine("Press enter to continue");
                        Console.ReadLine();
                        break;
                    }

                case 0:
                    Console.WriteLine("You know that's not an option.");
                    Console.WriteLine("\n\n");
                    Console.WriteLine("Press enter to continue");
                    Console.ReadLine();
                    break;

                default:
                    break;
                }
            }
            else
            {
                Console.Clear();
                Console.WriteLine();
                Console.WriteLine("You entered something that was not an option. And that's wrong. You're bad.");
                Console.WriteLine("\n\n");
                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
            }
        }
        public static void CollectInput(Farm farm)
        {
            Console.WriteLine("1. Chicken");
            Console.WriteLine("2. Cow");
            Console.WriteLine("3. Duck");
            Console.WriteLine("4. Pig");
            Console.WriteLine("5. Goat");
            Console.WriteLine("6. Ostrich");
            Console.WriteLine("7. Sheep");

            Console.WriteLine();
            Console.WriteLine("What are you buying today?");

            Console.Write("> ");
            string choice = Console.ReadLine();

            try
            {
                if (int.Parse(choice) <= 7 && int.Parse(choice) >= 1)
                {
                    switch (Int32.Parse(choice))
                    {
                    case 1:
                        ChooseChickenCoop.CollectInput(farm, new Chicken());
                        break;

                    case 2:
                        ChooseGrazingField.CollectInput(farm, new Cow());
                        break;

                    case 3:
                        ChooseDuckHouse.CollectInput(farm, new Duck());
                        break;

                    case 4:
                        ChooseGrazingField.CollectInput(farm, new Pig());
                        break;

                    case 5:
                        ChooseGrazingField.CollectInput(farm, new Goat());
                        break;

                    case 6:
                        ChooseGrazingField.CollectInput(farm, new Ostrich());
                        break;

                    case 7:
                        ChooseGrazingField.CollectInput(farm, new Sheep());
                        break;

                    default:
                        Console.WriteLine("Invalid option. Please try again.");
                        Thread.Sleep(2000);
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Invalid option. Please try again.");
                    Thread.Sleep(2000);
                    DisplayBanner();
                    PurchaseLivestock.CollectInput(farm);
                }
            }
            catch (FormatException)
            {
                Console.WriteLine("Invalid option. Please try again.");
                Thread.Sleep(2000);
                DisplayBanner();
                PurchaseLivestock.CollectInput(farm);
            }
        }