コード例 #1
0
        public static void CollectInput(Farm farm, ISeedProducing plant)
        {
            Console.Clear();

            for (int i = 0; i < farm.PlowedFields.Count; i++)
            {
                Console.WriteLine($"{i + 1}. Plowed Field");
            }
            // for (int j = 0; j < farm.NaturalFields.Count; j++)
            // {
            //     Console.WriteLine ($"{j + 1}. Natural Field");
            // }

            Console.WriteLine();

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

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

            farm.PlowedFields[choice - 1].AddResource(plant);

            /*
             *  Couldn't get this to work. Can you?
             *  Stretch goal. Only if the app is fully functional.
             */
            // farm.PurchaseResource<IGrazing>(animal, choice);
        }
コード例 #2
0
        public static void CollectInput(Farm farm, ISeedProducing seed)
        {
            Utils.Clear();
            // Loop throughh created Facilities and list them by number
            for (int i = 0; i < farm.NaturalFields.Count; i++)
            {
                Console.WriteLine($"{i + 1}. Natural Field ");
            }

            Console.WriteLine();

            // How can I output the type of animal chosen here?
            Console.WriteLine($"Place the seed where?");

            Console.Write("> ");
            // User Inputted number
            int choice = Int32.Parse(Console.ReadLine());

            // Using the Inputted Number in association with the Facility and adding seed
            farm.NaturalFields[choice - 1].AddResource(seed);

            /*
             *  Couldn't get this to work. Can you?
             *  Stretch goal. Only if the app is fully functional.
             */
            // farm.PurchaseResource<IGrazing>(animal, choice);
        }
コード例 #3
0
        public static void CollectInput(Farm farm, ISeedProducing plant)
        {
            Utils.Clear();

            for (int i = 0; i < farm.PlowedFields.Count; i++)
            {
                if (farm.PlowedFields[i].IsSpaceAvailable() > 0)
                {
                    Console.WriteLine($"{i + 1}. Plowed Field ({farm.PlowedFields[i].PlantsInFacility()} Plant(s) in the fields)");
                    farm.PlowedFields[i].PlantsGroups();
                }
            }

            Console.WriteLine();

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

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

            farm.PlowedFields[choice - 1].AddResource(plant);

            /*
             *  Couldn't get this to work. Can you?
             *  Stretch goal. Only if the app is fully functional.
             */
            // farm.PurchaseResource<IPlowed>(plant, choice);
        }
コード例 #4
0
        public static void CollectInput(Farm farm, ISeedProducing plant)
        {
            Console.Clear();

            for (int i = 0; i < farm.PlowedFields.Count; i++)
            {
                Console.WriteLine($"{i + 1}. Plowed Field");
            }

            Console.WriteLine();
            Console.WriteLine($"Place the {plant.Type} where?");

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

            // farm.GrazingFields[choice].AddResource(animal);  TODO: Have this bug for boilerplate
            farm.PlowedFields[choice - 1].AddResource(plant);

            /*
             *  Couldn't get this to work. Can you?
             *  Stretch goal. Only if the app is fully functional.
             *      https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/introduction-to-generics
             */
            // farm.PurchaseResource<IGrazing>(animal, choice-1);
        }
コード例 #5
0
        // loop through the natural fields and list options for fields to plant
        public static void CollectInput(Farm farm, ISeedProducing seed)
        {
            Utils.Clear();
            for (int i = 0; i < farm.PlowedFields.Count; i++)
            {
                Console.WriteLine($"{i + 1}. Plowed Field has {farm.PlowedFields[i]._seeds.Count} Plants");

                var seedreport = from plowedseeds in farm.PlowedFields[i]._seeds
                                 group plowedseeds by plowedseeds.Type into seedgroup
                                 select  new Dictionary <string, int>()
                {
                    { seedgroup.Key, seedgroup.Count() }
                };


                foreach (Dictionary <string, int> plowedseeds in seedreport)
                {
                    foreach (KeyValuePair <string, int> seedgroup in plowedseeds)
                    {
                        Console.WriteLine($"This field has {seedgroup.Value} {seedgroup.Key}s");
                    }
                }
                ;
            }
            Console.WriteLine($"Place the Seed Where?");
            Console.WriteLine("> ");
            int choice = Int32.Parse(Console.ReadLine());

            farm.PlowedFields[choice - 1].AddResource(seed);
        }
コード例 #6
0
 public override void ProcessResources()
 {
     System.Console.WriteLine("Processing resources...");
     Resources.ForEach(resource => {
         ISeedProducing seedingPlant = (ISeedProducing)resource;
         System.Console.WriteLine($"{seedingPlant.Harvest()} seeds were produced");
     });
 }
コード例 #7
0
        public static void CollectInput(Farm farm, ISeedProducing plant)
        {
            Console.Clear();
            if (farm.AvailablePlowedFields.Count() == 0)
            {
                Console.WriteLine("You need to create a Plowed Field before you can purchase a plant.");
            }

            for (int i = 0; i < farm.PlowedFields.Count; i++)
            {
                if (farm.PlowedFields[i].GetCount() < farm.PlowedFields[i].Capacity)
                {
                    Console.WriteLine($"{i + 1}. Plowed Field ({farm.PlowedFields[i].GetCount()} plants)");
                    farm.PlowedFields[i].GroupPlants();
                }
            }

            Console.WriteLine();

            // How can I output the type of animal chosen here?
            try
            {
                if (farm.AvailablePlowedFields.Count() != 0)
                {
                    Console.WriteLine($"Place the plant where?");
                    Console.Write("> ");
                    int choice = Int32.Parse(Console.ReadLine());
                    if (farm.PlowedFields[choice - 1].GetCount() < farm.PlowedFields[choice - 1].Capacity)
                    {
                        farm.PlowedFields[choice - 1].AddResource(plant);
                        if (farm.PlowedFields[choice - 1].GetCount() >= farm.PlowedFields[choice - 1].Capacity)
                        {
                            farm.AvailablePlowedFields.Remove(farm.PlowedFields[choice - 1]);
                        }
                        Console.WriteLine("Plant Added To Field");
                    }
                }
            }
            catch (System.FormatException)
            {
                Console.WriteLine($"Invalid option");
                Console.WriteLine();
            }
            catch (System.ArgumentOutOfRangeException)
            {
                Console.WriteLine($"Invalid Number");
                Console.WriteLine();
            }



            /*
             *  Couldn't get this to work. Can you?
             *  Stretch goal. Only if the app is fully functional.
             */
            // farm.PurchaseResource<IGrazing>(animal, choice);
        }
コード例 #8
0
        public static void CollectInput(Farm farm, ISeedProducing plant)
        {
            Console.Clear();

            if (farm.PlowedFields.Count == 0)
            {
                Console.WriteLine("No locations available. Press any key to continue");
                Console.Write("> ");
                Console.ReadLine();
            }
            else
            {
                for (int i = 0; i < farm.PlowedFields.Count; i++)
                {
                    Console.WriteLine($"{i + 1}. Plowed Field currently contains {farm.PlowedFields[i].PlantCount()} plant(s). The capacity is {farm.PlowedFields[i].Capacity} plants");
                    farm.PlowedFields[i].GetPlantTypes();
                    Console.WriteLine();
                }

                Console.WriteLine();

                Console.WriteLine($"Place plant where?");

                Console.Write("> ");
                var choice = 0;
                while (!int.TryParse(Console.ReadLine(), out choice))
                {
                    Console.WriteLine("That was invalid. Enter a valid selection.");
                }
                // int choice = Int32.Parse(Console.ReadLine()) - 1;

                if (choice > farm.PlowedFields.Count)
                {
                    Console.WriteLine("Incorrect Selection. Press any key to continue");
                    Console.Write("> ");
                    Console.ReadLine();
                }
                else
                {
                    if (farm.PlowedFields[choice - 1].Capacity == farm.PlowedFields[choice - 1].PlantCount())
                    {
                        Console.WriteLine("Too many plants. Press any key to continue");
                        Console.Write("> ");
                        Console.ReadLine();
                    }
                    else
                    {
                        farm.PlowedFields[choice - 1].AddResource(plant);
                        Console.WriteLine($"Your plant was placed in the Plowed Field ! Press any key to continue");
                        Console.ReadLine();
                    }
                }
            }
        }
コード例 #9
0
 public static void CollectInput(Farm farm, ISeedProducing seed)
 {
     for (int i = 0; i < farm.GrazingFields.Count; i++)
     {
         Console.Clear();
         foreach (GrazingField gf in farm.GrazingFields)
         {
             if (gf.Animals.GetType().Name.ToString() == "ICompost")
             {
                 Console.WriteLine($"{i + 1}. {farm.GrazingFields[i]}");
             }
         }
     }
 }
コード例 #10
0
        public static void CollectInput(Farm farm, ISeedProducing plant)
        {
            foreach (PlowedField field in farm.PlowedFields)
            {
                if (field.Plants.Count < field.Capacity)
                {
                    StringBuilder output = new StringBuilder();
                    output.Append($"{farm.PlowedFields.IndexOf(field)+1}. Plowed Field (");
                    if (field.Plants.Count == 0)
                    {
                        output.Append("0");
                    }
                    else
                    {
                        //group by
                        List <TypeCounter> plantCount = (
                            from flower in field.Plants
                            group flower by flower.Type into PlantGroup
                            select new TypeCounter {
                            Type = PlantGroup.Key,
                            Count = PlantGroup.Count()
                        }
                            ).ToList();
                        foreach (TypeCounter entry in plantCount)
                        {
                            // TODO: remove trailing comma
                            output.Append($"{entry.Count} {entry.Type},");
                        }
                    }
                    output.Append($" of {field.Capacity} rows)");
                    Console.WriteLine(output);
                    //Console.WriteLine ($"{farm.PlowedFields.IndexOf(field)+1}. Plowed Field ({field.Plants.Count} of {field.Capacity} rows)");
                }
            }

            Console.WriteLine();

            Console.WriteLine($"Plant the seeds where?");

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

            try {
                farm.PlowedFields[choice - 1].AddResource(farm, plant);
            } catch (ArgumentOutOfRangeException) {
                Console.WriteLine($"Invalid option: {choice}");
                Console.WriteLine("Press any key to go back to main menu.");
                Console.ReadLine();
            }
        }
コード例 #11
0
        public static void CollectInput(Farm farm, ISeedProducing plant)
        {
            Utils.Clear();

            bool Planted = false;

            while (Planted == false)
            {
                //Loop for printing fields with if for seeing if at capacity
                for (int i = 0; i < farm.PlowedFields.Count; i++)
                {
                    // if(i > 0){
                    Console.WriteLine(farm.PlowedFields[i].Capacity == farm.PlowedFields[i].currentNumberInField
                        ? $"{i + 1}. Plowed Field (Full)"
                        : $"{i + 1}. Plowed Field ({farm.PlowedFields[i].currentNumberInField} plants)");
                }

                Console.WriteLine();

                // How can I output the type of animal chosen here?
                Console.WriteLine($"Plant the {plant.GetType().Name} seeds where?");

                Console.Write("> ");
                try
                {
                    int choice = Int32.Parse(Console.ReadLine());
                    /*Checking to see if the field has room for the animal*/
                    if (farm.PlowedFields[choice - 1].currentNumberInField == farm.PlowedFields[choice - 1].Capacity)
                    {
                        Console.WriteLine("**** That facility is not large enough ****");
                        Console.WriteLine("****     Please choose another one      ****");
                        choice = Int32.Parse(Console.ReadLine());
                    }
                    /*If so adding to the field*/
                    else
                    {
                        farm.PlowedFields[choice - 1].AddResource(plant);
                        //Console.WriteLine("Break Point");
                        Console.WriteLine("Plant added to field");
                        Console.ReadLine();
                        Planted = true;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Please enter only numbers");
                }
            }
        }
コード例 #12
0
        public static void CollectInput(Farm farm, ISeedProducing seed, bool clear = true)
        {
            bool allFull = farm.NaturalFields.All(field => field.SeedCount == field.Capacity);

            if (allFull)
            {
                Console.WriteLine("No facilities available, press enter to continue");
                Console.ReadLine();
            }
            while (!allFull)
            {
                Utils.Clear();

                for (int i = 0; i < farm.NaturalFields.Count; i++)
                {
                    Console.Write($"{i + 1}. Natural Field: Total: {farm.NaturalFields[i].SeedCount} of {farm.NaturalFields[i].Capacity} (");
                    farm.NaturalFields[i].listSeeds();
                    Console.WriteLine(")");
                }

                Console.WriteLine();

                // How can I output the type of animal chosen here?
                Console.WriteLine($"Place the seed where?");

                Console.Write("> ");
                try
                {
                    int choice = Int32.Parse(Console.ReadLine());
                    if (farm.NaturalFields[choice - 1].SeedCount < farm.NaturalFields[choice - 1].Capacity)
                    {
                        farm.NaturalFields[choice - 1].AddResource(seed);
                        break;
                    }
                    else
                    {
                        Console.WriteLine("This facility is full, please choose another one");
                        Console.WriteLine("Press enter to continue");
                        Console.ReadLine();
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Wrong input, please chose another.");
                    Console.WriteLine("Press enter to continue");
                    Console.ReadLine();
                }
            }
        }
コード例 #13
0
        public void ProcessResults(List <IResource> resProcessed)
        {
            Dictionary <string, double> seedsProduced = new Dictionary <string, double>();

            resProcessed.ForEach(plant => {
                ISeedProducing resource = (ISeedProducing)plant;
                try
                {
                    seedsProduced.Add(resource.GetType().Name, resource.Harvest());
                }
                catch (Exception)
                {
                    seedsProduced[resource.GetType().Name] += resource.Harvest();
                }
            });
            foreach (KeyValuePair <string, double> plant in seedsProduced)
            {
                System.Console.WriteLine($"{plant.Value} {plant.Key} seeds were produced");
            }
        }
コード例 #14
0
        public static void CollectInput(Farm farm, ISeedProducing plant)
        {
            Console.Clear();

            for (int i = 0; i < farm.PlowedFields.Count; i++)
            {
                Console.WriteLine($"{i + 1}. Plowed Field");
            }

            Console.WriteLine();

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

            Console.Write("> ");
            int choiceInput = Int32.Parse(Console.ReadLine());
            int choice      = choiceInput - 1;

            farm.PlowedFields[choice].AddResource(plant);
        }
        public static void CollectInput(Farm farm, ISeedProducing seed)
        {
            Console.Clear();

            List <PlowedField> availablePlowedFields = new List <PlowedField>();

            for (int i = 0; i < farm.PlowedFields.Count; i++)
            {
                if ((farm.PlowedFields[i].Capacity) > farm.PlowedFields[i].GetPlantCount())
                {
                    availablePlowedFields.Add(farm.PlowedFields[i]);
                }
            }

            int fieldCount = 1;

            if (availablePlowedFields.Count == 0)
            {
                Console.WriteLine("You do not have any available fields to plant this seed.");
                Console.ReadLine();
            }

            for (int i = 0; i < availablePlowedFields.Count; i++)
            {
                while (fieldCount > 0)
                {
                    Console.WriteLine($"{i + 1}: This field currently has {availablePlowedFields[i].GetPlantCount()} rows of plants with a capacity of {availablePlowedFields[i].Capacity} rows.");
                    availablePlowedFields[i].getSesameSeeds();
                    availablePlowedFields[i].getSunflowerSeed();
                    Console.WriteLine($"Press 1 to plant your {seed.GetName()} seeds in this field.");
                    Console.Write("> ");
                    int choice     = Int32.Parse(Console.ReadLine());
                    int realChoice = choice - 1;
                    availablePlowedFields[realChoice].AddResource(seed);
                    Console.WriteLine($"1 row of plants have been added to this field. You currently have {availablePlowedFields[realChoice].GetPlantCount()} row(s) in this field. Press the 'Enter' key to continue.");
                    fieldCount--;
                    Console.ReadLine();
                }
            }
        }
コード例 #16
0
        public static void CollectInput(Farm farm, ISeedProducing seed)
        {
            Console.Clear();
            var fieldsWithSpace = farm.PlowedFields.FindAll(field => field.AvailableSpots > 0);

            if (fieldsWithSpace.Count < 1)
            {
                Console.WriteLine("There are no Plowed Fields with space available");
                Console.WriteLine("Press any button to continue.");
                Console.ReadLine();
                Console.Clear();
                Program.DisplayBanner();
                PurchaseSeed.CollectInput(farm);
            }

            for (int i = 0; i < fieldsWithSpace.Count; i++)
            {
                Console.WriteLine($"{i + 1}. {fieldsWithSpace[i].Name} - Current Plants: {fieldsWithSpace[i].currentPlants} | Available Rows: {fieldsWithSpace[i].AvailableSpots}");
                fieldsWithSpace[i].ListByType();
            }

            Console.WriteLine();

            Console.WriteLine($"Place the row of seeds where?");

            Console.Write("> ");

            try
            {
                int choice = Int32.Parse(Console.ReadLine()) - 1;

                farm.PlowedFields[choice].AddResource(seed);
            }
            catch (Exception)
            {
                Program.ShowMessage("Invalid Input");
            }
        }
コード例 #17
0
        public static void CollectInput(Farm farm, ISeedProducing plant)
        // clear the terminal
        {
            Utils.Clear();
            // print out all types of Natural fields
            for (int i = 0; i < farm.NaturalFields.Count; i++)
            {
                Console.WriteLine($"{i + 1}. Natural Field: {farm.NaturalFields[i]}");
            }

            Console.WriteLine();

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

            Console.Write("> ");
            // read which natural field option is selected
            int choice = Int32.Parse(Console.ReadLine());

            // add the plant to the field
            if (plant is Sunflower || plant is Wildflower)
            {
                farm.NaturalFields[choice - 1].AddResource(plant);
                Console.WriteLine("You have spread your seed into a Natural field. Press any key to return home.");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("Please choose an appropriate field.");
                Console.WriteLine("Press any key to re-select your field.");
                Console.ReadLine();
                // make list to select again
                CollectInput(farm, plant);
            }
            Console.WriteLine();
        }
コード例 #18
0
        public static void CollectInput(Farm farm, ISeedProducing seed)
        {
            Utils.Clear();

            for (int i = 0; i < farm.PlowedFields.Count; i++)
            {
                try {
                    // farm.PlowedFields[i].GetTotal() < farm.PlowedFields[i].Capacity

                    Console.WriteLine($"{i + 1}. Plowed Field ({farm.PlowedFields[i].GetTotal()} plants)");
                    Console.WriteLine($"{farm.PlowedFields[i].SesameCount()} Sesame");
                    Console.WriteLine($"{farm.PlowedFields[i].SunflowerCount()} Sunflower");
                }

                catch (Exception)
                {
                    Console.WriteLine("All fields are full. Please go back to main menu to create a new field!");
                    Console.WriteLine();
                }
            }
            // IResource.Type
            Console.WriteLine($"Where should we place the seed?");

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

            if (farm.PlowedFields[choice - 1].GetTotal() < farm.PlowedFields[choice - 1].Capacity)
            {
                farm.PlowedFields[choice - 1].AddResource(seed);
            }
            else
            {
                Console.WriteLine("This field is full.");
                Thread.Sleep(2000);
            }
        }
        public static void CollectInput(Farm farm, ISeedProducing plant)
        {
            Console.Clear();

            Console.WriteLine($"How many {plant.Type}s would you like to plant?");

            // store that number in the variable "number"
            // Use Enumberable.Repeat() to put x("number") amount of plants("plant") in new list named "manyPlants"
            Console.Write("> ");

            int number = Int32.Parse(Console.ReadLine());

            List <ISeedProducing> manyPlants = Enumerable.Repeat(plant, number).ToList();

            Console.Clear();

            for (int i = 0; i < farm.PlowedFields.Count; i++)
            {
                if (farm.PlowedFields[i].plantCount() == 1)
                {
                    Console.WriteLine($"{i + 1}. Plowed Field ({farm.PlowedFields[i].plantCount()} row of plants)");
                }
                else if (farm.PlowedFields[i].plantCount() < farm.PlowedFields[i].Capacity)
                {
                    Console.WriteLine($"{i + 1}. Plowed Field ({farm.PlowedFields[i].plantCount()} rows of plants)");
                }
                // else
                // {
                //   Console.WriteLine($"{i + 1}. Plowed Field is full. ({farm.PlowedFields[i].plantCount()} rows of plants)");
                // }
            }
            Console.WriteLine();

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

            Console.Write("> ");
            int choice = Int32.Parse(Console.ReadLine()) - 1;

            if (farm.PlowedFields[choice].plantCount() + manyPlants.Count() <= farm.PlowedFields[choice].Capacity)
            {
                farm.PlowedFields[choice].AddResource(manyPlants);
            }
            else
            {
                Console.Clear();
                Console.WriteLine($@"
~ I'm sorry! That facility can only hold ({farm.PlowedFields[0].Capacity}) plants ~

************************************************************************
**************      Please choose another facility.     ****************
********** If there are no other plowed fields, build one.  ***********
************************************************************************

-----------------------((press enter to continue))----------------------
");
                Console.ReadLine();
                Console.Clear();
                // after user hits enter ask if they want to create a new field
                Console.WriteLine($@"
 _______________________________________________
| Would you like to create a new Plowed Field? |
|         Press 1 for yes or 2 for no           |
 -----------------------------------------------
");
                Console.Write("> ");
                // collect the user's input and store it in the string "input"
                string input = Console.ReadLine();
                // parse the string and create a switch case
                switch (Int32.Parse(input))
                {
                // create a new plowedField and add it to the farm.
                // go to the ChoosePlowedField menu and pass the animal and farm
                case 1:
                    farm.AddPlowedField(new PlowedField());
                    Console.Clear();
                    Console.WriteLine("Success! One Plowed Field Added. Press enter to continue.");
                    Console.ReadLine();
                    ChoosePlowedField.CollectInput(farm, plant);
                    break;

                case 2:
                    break;
                }
            }
        }
        public static void CollectInput(Farm farm, ISeedProducing plant)
        {
            Utils.Clear();


            List <PlowedField> openPlowedFields = farm.PlowedFields.Where(field => field.PlantsCount() < field.Capacity).ToList();


            Console.WriteLine("0. Return to Main Menu");


            for (int i = 0; i < openPlowedFields.Count; i++)
            {
                Console.WriteLine($"{i + 1}. Plowed Field (Total Plants: {openPlowedFields[i].PlantsCount()} Total Sesame: {openPlowedFields[i].SesameCount()} Total Sunflower: {openPlowedFields[i].SunflowerCount()}) ");
            }


            Console.WriteLine();

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


            Console.Write("> ");

            //Checks that the correct input was entered.
            while (true)
            {
                try
                {
                    int choice = Int32.Parse(Console.ReadLine());
                    if (choice >= 1 && choice <= openPlowedFields.Count)
                    {
                        openPlowedFields[choice - 1].AddResource(plant);
                        Console.WriteLine("The plant was successfully added to the plowed field.");
                        Thread.Sleep(2000);
                        break;
                    }
                    else if (choice == 0)
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Incorrect input.  Please try again.");
                        Console.Write("> ");
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Incorrect input.  Please try again.");
                    Console.Write("> ");
                }
            }

            /*
             *  Couldn't get this to work. Can you?
             *  Stretch goal. Only if the app is fully functional.
             */
            // farm.PurchaseResource<IGrazing>(animal, choice);
        }
コード例 #21
0
 public void AddResource(ISeedProducing resource)
 {
     _resources.Add((IResource)resource);
 }
コード例 #22
0
        public static void CollectInput(Farm farm, ISeedProducing plant)
        {
            var fullPlowedFields = new List <int>();

            // Make a list of available fields
            Console.Clear();
            for (int i = 0; i < farm.PlowingFields.Count; i++)
            {
                if (farm.PlowingFields[i].PlantCount < farm.PlowingFields[i].Capacity)
                {
                    // Calculate Plant Count By Type
                    var typesList = (from p in farm.PlowingFields[i].PlantsList
                                     group p by p.Type into g
                                     let count = g.Count()
                                                 select new { Value = g.Key, Count = count });



                    // Print Message
                    Console.WriteLine($"{i + 1}. Plowing Field {farm.PlowingFields[i].id} has {farm.PlowingFields[i].PlantCount} plant rows");
                    if (farm.PlowingFields[i].PlantCount > 0)
                    {
                        foreach (var type in typesList)
                        {
                            Console.WriteLine($"     {type.Value}:  {type.Count}");
                        }
                    }
                }
                else
                {
                    fullPlowedFields.Add(i);
                };
            }
            if (fullPlowedFields.Count == farm.PlowingFields.Count)
            {
                Console.WriteLine("Please create a new facility");
                CreateFacility.CollectInput(farm);
            }
            else
            {
                Console.WriteLine($"Place the seeds where?");
                Console.Write("> ");
                int choice = Int32.Parse(Console.ReadLine());
                if (farm.PlowingFields[choice - 1].PlantCount < farm.PlowingFields[choice - 1].Capacity)
                {
                    farm.PlowingFields[choice - 1].AddResource(plant);
                }
                else
                {
                    Console.WriteLine("Please select an available facility option");
                    CreateFacility.CollectInput(farm);
                }
                Console.WriteLine();
                // How can I output the type of animal chosen here?

                /*
                 *   Couldn't get this to work. Can you?
                 *   Stretch goal. Only if the app is fully functional.
                 */
                // farm.PurchaseResource<IGrazing>(animal, choice);
            }
        }
コード例 #23
0
        public static void CollectInput(Farm farm, ISeedProducing seed, bool clear = true)
        {
            bool allFull = farm.PlowedFields.All(field => field.GetCount == field.Capacity);

            if (allFull)
            {
                Console.WriteLine("No facilities available, press enter to continue");
                Console.ReadLine();
            }
            while (!allFull)
            {
                Utils.Clear();

                for (int i = 0; i < farm.PlowedFields.Count; i++)
                {
                    Console.Write($"{i + 1}. Plowed Field: Total: {farm.PlowedFields[i].GetCount} of {farm.PlowedFields[i].Capacity} (");
                    farm.PlowedFields[i].listSeeds();
                    Console.WriteLine(")");
                }

                Console.WriteLine();

                // How can I output the type of animal chosen here?
                Console.WriteLine($"Place the seed where?");

                Console.Write("> ");
                try
                {
                    int choice = Int32.Parse(Console.ReadLine());
                    if (farm.PlowedFields[choice - 1].GetCount < farm.PlowedFields[choice - 1].Capacity)
                    {
                        farm.PlowedFields[choice - 1].AddResource(seed);
                        break;
                    }
                    else
                    {
                        Console.WriteLine("This facility is full, please choose another one");
                        Console.WriteLine("Press enter to continue");
                        Console.ReadLine();
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Wrong input, please chose another.");
                    Console.WriteLine("Press enter to continue");
                    Console.ReadLine();
                }

                /*
                 *  Couldn't get this to work. Can you?
                 *  Stretch goal. Only if the app is fully functional.
                 */
                // farm.PurchaseResource<IGrazing>(animal, choice);
            }
            // Utils.Clear();

            // if (farm.GrazingFields.Count < 1)
            // {
            //     Console.WriteLine("Facility doesn't exist for selected animal.");
            //     Console.WriteLine("Press return key to go back to main menu.");
            //     Console.ReadLine();
            //     Utils.Clear();
            // }
            // else
            // {

            //     for (int i = 0; i < farm.GrazingFields.Count; i++)
            //     {
            //         Console.WriteLine($"{i + 1}. Grazing Field ({farm.GrazingFields[i].AnimalCount} {(farm.GrazingFields[i].AnimalCount == 1 ? "animal" : "animals")})");
            //     }

            //     Console.WriteLine();

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

            //     Console.Write("> ");
            //     int choice = Int32.Parse(Console.ReadLine());
            //     choice = choice - 1;
            //     int currentListCount = farm.GrazingFields[choice].AnimalCount;
            //     int availableSpace = Convert.ToInt32(farm.GrazingFields[choice].Capacity) - currentListCount;
            //     int evaluatedAvailableSpace = Math.Sign(availableSpace);
            //     if (evaluatedAvailableSpace == 1)
            //     {
            //         farm.GrazingFields[choice].AddResource(animal);
            //     }
            //     else
            //     {
            //         // Console.Clear();
            //         Console.WriteLine("Facility is full. Please choose another facility.");
            //         Console.ReadLine();

            //         ChooseGrazingField.CollectInput(farm, animal, false);
            //     }

            //     // farm.GrazingFields[choice].AddResource(animal);

            //     /*
            //         Couldn't get this to work. Can you?
            //         Stretch goal. Only if the app is fully functional.
            //      */
            //     // farm.PurchaseResource<IGrazing>(animal, choice);
            // }
        }
コード例 #24
0
 public void AddToHopper(ISeedProducing resourceToAdd)
 {
     _hopper.Add(resourceToAdd);
 }
コード例 #25
0
 public void AddResource(ISeedProducing seed)
 {
     seedToProcess.Add(seed);
 }
コード例 #26
0
        public static void CollectInput(Farm farm, ISeedProducing plant)
        {
            Console.Clear();
            if (farm.AvailablePlowedFields.Count() == 0 && farm.AvailableNaturalFields.Count() == 0)
            {
                Console.WriteLine("You need to create a Plowed Field or a Natural Field before you can purchase a sunflower.");
            }

            for (int i = 0; i < farm.PlowedFields.Count; i++)
            {
                if (farm.PlowedFields[i].GetCount() < farm.PlowedFields[i].Capacity)
                {
                    Console.WriteLine($"{i + 1}. Plowed Field ({farm.PlowedFields[i].GetCount()} plants)");
                    farm.PlowedFields[i].GroupPlants();
                }
            }

            for (int i = 0; i < farm.NaturalFields.Count; i++)
            {
                if (farm.NaturalFields[i].GetCount() < farm.NaturalFields[i].Capacity)
                {
                    Console.WriteLine($"{i + 1 + farm.PlowedFields.Count()}. Natural Field ({farm.NaturalFields[i].GetCount()} plants)");
                    farm.NaturalFields[i].GroupPlants();
                }
            }

            Console.WriteLine();


            Console.WriteLine();

            try
            {
                if (farm.AvailableNaturalFields.Count() != 0 || farm.AvailablePlowedFields.Count() != 0)
                {
                    Console.WriteLine($"Place the sunflower where?");
                    Console.Write("> ");
                    int choice = Int32.Parse(Console.ReadLine());


                    if (choice <= farm.PlowedFields.Count())
                    {
                        farm.PlowedFields[choice - 1].AddResource(plant);
                        Console.WriteLine("Sunflower Added To Plowed field");
                        if (farm.PlowedFields[choice - 1].GetCount() >= farm.PlowedFields[choice - 1].Capacity)
                        {
                            farm.AvailablePlowedFields.Remove(farm.PlowedFields[choice - 1]);
                        }
                    }
                    else if (choice > farm.PlowedFields.Count())
                    {
                        farm.NaturalFields[(choice - 1) - farm.PlowedFields.Count()].AddResource(plant);
                        Console.WriteLine("Sunflower Added To Natural field");
                        if (farm.NaturalFields[(choice - 1) - farm.PlowedFields.Count].GetCount() >= farm.NaturalFields[(choice - 1) - farm.PlowedFields.Count].Capacity)
                        {
                            farm.AvailableNaturalFields.Remove(farm.NaturalFields[(choice - 1) - farm.PlowedFields.Count]);
                        }
                    }
                }
            }
            catch (System.FormatException)
            {
                Console.WriteLine($"Invalid option");
                Console.WriteLine();
            }
            catch (System.ArgumentOutOfRangeException)
            {
                Console.WriteLine($"Invalid Number");
                Console.WriteLine();
            }
        }
コード例 #27
0
        public static void CollectInput(Farm farm, ISeedProducing seed)
        {
            Console.Clear();

            for (int i = 0; i < farm.PlowedFields.Count; i++)
            {
                if (farm.PlowedFields[i].seedCount() != farm.PlowedFields[i].Capacity)
                {
                    if (farm.PlowedFields[i].seedCount() > 0)
                    {
                        Console.WriteLine($"{i + 1}. Plowed Field ({farm.PlowedFields[i].SeedList()})");
                    }
                    else
                    {
                        Console.WriteLine($"{i + 1}. Plowed Field {farm.PlowedFields[i]}");
                    }
                }
                else
                {
                    Console.WriteLine($"{i + 1}. Plowed Field {farm.PlowedFields[i].shortId()}");
                }
            }

            Console.WriteLine();

            // How can I output the type of seed chosen here?
            Console.WriteLine($"Place the seed in which plowed field?");

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

            if (choice != "" && int.TryParse(choice, out int input))
            {
                int seedCount = farm.PlowedFields[input - 1].seedCount();
                if (farm.PlowedFields[input - 1].seedCount() != farm.PlowedFields[input - 1].Capacity)
                {
                    Console.Clear();
                    Console.WriteLine("\n\n\n");
                    farm.PlowedFields[input - 1].AddResource(seed);
                    Console.WriteLine($"Looks like you're the proud owner of a single {seed}!");
                    Console.WriteLine("\n\n");
                    Console.WriteLine("Press enter to continue");
                    Console.ReadLine();
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("\n\n\n");
                    Console.WriteLine($"Plowed Field {farm.PlowedFields[input - 1].shortId()} is daggum full! Y'heer??");
                    Console.WriteLine("\n\n");
                    Console.WriteLine("Press enter to continue");
                    Console.ReadLine();
                }
            }
            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();
            }

            /*
             *  Couldn't get this to work. Can you?
             *  Stretch goal. Only if the app is fully functional.
             */
            // farm.PurchaseResource<IGrazing>(seed, choice);
        }