示例#1
0
        public static void CollectInput(Farm farm)
        {
            Console.WriteLine("1. Sesame");
            Console.WriteLine("2. Sunflower");
            Console.WriteLine("3. Wildflower");

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

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

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

            case 2:
                ChoosePlantField.CollectInput(farm, new Sunflower());
                break;

            case 3:
                ChoosePlantField.CollectInput(farm, new Wildflower());
                break;

            default:
                break;
            }
        }
        public static void CollectInput(Farm farm)
        {
            var plantList = new List <IResource>();

            plantList.Add(new Sesame());
            plantList.Add(new Sunflower());
            plantList.Add(new Wildflower());

            foreach (var plant in plantList)
            {
                Console.WriteLine($"{plantList.IndexOf(plant) + 1}. {plant}");
            }

            Console.WriteLine();
            Console.WriteLine("Choose seed to purchase.");

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

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

            case 2:
                ChoosePlantField.CollectInput(farm, new Sunflower(), 3);
                break;

            case 3:
                ChoosePlantField.CollectInput(farm, new Wildflower(), 2);
                break;

            default:
                break;
            }
        }
示例#3
0
        public static void CollectInput(Farm farm, IPlowing plant)
        {
            Console.Clear();

            if (farm.PlowedFields.Count() == 0 || farm.PlowedFields.Where(field => field.Plants.Count == field.Capacity).ToList().Count == farm.PlowedFields.Count())
            {
                Console.WriteLine("There are no available plowed fields. Try creating a new one.");
                Console.WriteLine("Press return... or else");
                Console.ReadLine();
            }
            else
            {
                for (int i = 0; i < farm.PlowedFields.Count; i++)
                {
                    // Only display plowed fields that have room
                    if (farm.PlowedFields[i].Plants.Count < farm.PlowedFields[i].Capacity)
                    {
                        Console.WriteLine("=================================================");
                        Console.WriteLine($"{i + 1}. Plowed Field. Current Plant Count: {farm.PlowedFields[i].Plants.Count}");

                        // Group Plowed Fields by their type to display their counts
                        List <IGrouping <string, IPlowing> > groupedPlowedFields = farm.PlowedFields[i].Plants.GroupBy(plnt => plnt.Type).ToList();

                        foreach (IGrouping <string, IPlowing> plnt in groupedPlowedFields)
                        {
                            Console.WriteLine($"{plnt.Key}: {plnt.Count()} rows");
                        }
                        Console.WriteLine("=================================================");
                    }
                }

                Console.WriteLine();

                // How can I output the type of plant chosen here?
                Console.WriteLine($"Place the {plant.Type} where?");

                Console.Write("> ");
                try
                {
                    int choice = Int32.Parse(Console.ReadLine());


                    if (farm.PlowedFields[choice - 1].Plants.Count < farm.PlowedFields[choice - 1].Capacity)
                    {
                        farm.PlowedFields[choice - 1].AddResource(plant);
                    }
                    else if (farm.PlowedFields.Where(field => field.Plants.Count < field.Capacity).ToList().Count > 0)
                    {
                        Console.Write("Facility is full. Please select another facility. Press return to continue...");
                        Console.ReadLine();
                        ChoosePlantField.CollectInput(farm, plant);
                    }
                    else
                    {
                        Console.Write("All facilities full. Press return to continue...");
                        Console.ReadLine();
                    }
                }
                catch (System.FormatException)
                {
                    Console.WriteLine("Please enter one of the specified options...\nI love you.\nPress return to continue");
                    Console.ReadLine();
                    ChoosePlantField.CollectInput(farm, plant);
                }
                catch (System.ArgumentOutOfRangeException)
                {
                    Console.WriteLine("The plant field you selected does not exist\nPress return to continue");
                    Console.ReadLine();
                    ChoosePlantField.CollectInput(farm, plant);
                }
            }
        }