public static void CollectInput(Farm farm) { Console.WriteLine("1. Seed Harvester"); Console.WriteLine("2. Compost Harvester"); Console.WriteLine(); Console.WriteLine("Choose equipment to use"); Console.Write("> "); try { string input = Console.ReadLine(); switch (Int32.Parse(input)) { case 1: SeedHarvester seedHarvester = new SeedHarvester(); ChoosePlowedFieldForSeed.CollectInput(farm, seedHarvester); break; case 2: CompostHarvester compostHarvester = new CompostHarvester(); ChooseNaturalFieldForCompost.CollectInput(farm, compostHarvester); break; default: break; } } catch { Console.WriteLine("Incorrect Input, please hit any key to return to main menu"); // Console.ReadLine(); } }
public static void CollectInput(Farm farm) { // Console.Clear(); if (farm.NaturalFields.Count == 0 && farm.PlowedFields.Count == 0) { Console.WriteLine("*** Oops! You don't have any seeds Harvesting facilities! ***"); Console.WriteLine("*** Press return key to go back to main menu."); Console.ReadLine(); } else { try { // Show available facilities and plant counts SeedHarvester Equipment = new SeedHarvester(); for (int p = 0; p < farm.NaturalFields.Count; p++) { var groupPlants = farm.NaturalFields[p].Resources.GroupBy( currentPlant => currentPlant.Type ); var plantsString = ""; foreach (var currentPlantGroup in groupPlants) { plantsString += currentPlantGroup.Count() + " " + currentPlantGroup.Key + ","; } ; Console.WriteLine($"{p + 1}. Natural Field ({plantsString})"); } for (int p = 0; p < farm.PlowedFields.Count; p++) { var groupPlants = farm.PlowedFields[p].Resources.GroupBy( currentPlant => currentPlant.Type ); var plantsString = ""; foreach (var currentPlantGroup in groupPlants) { plantsString += currentPlantGroup.Count() + " " + currentPlantGroup.Key + ","; } ; Console.WriteLine($"{farm.NaturalFields.Count + p + 1}. Plowed Field ({plantsString})"); } Console.WriteLine(); Console.WriteLine($"Which field you want to harvest?"); int field = Int32.Parse(Console.ReadLine()); IEnumerable <IGrouping <string, IResource> > groupedPlants; if (field <= farm.NaturalFields.Count) { Console.WriteLine("The following plants in that field:"); groupedPlants = from plant in farm.NaturalFields[field - 1].Resources where plant.Type == "Sesame" || plant.Type == "SunFlower" group plant by plant.Type into newGroup select newGroup; } else { Console.WriteLine("The following plants in that field:"); groupedPlants = from plant in farm.PlowedFields[field - farm.NaturalFields.Count - 1].Resources where plant.Type == "Sesame" || plant.Type == "SunFlower" group plant by plant.Type into newGroup select newGroup; } if (groupedPlants.Count() == 0) { Console.WriteLine("There are no plants for harvesting..."); Console.ReadLine(); } else { int j = 1; foreach (var currentPlantGroup in groupedPlants) { Console.WriteLine($"{j}. {currentPlantGroup.Count() + " " + currentPlantGroup.Key}"); j++; } ; Console.WriteLine(); Console.WriteLine("Which Plants should be harvested?"); Console.Write("> "); int inputType = Int32.Parse(Console.ReadLine()); Console.WriteLine(); Console.WriteLine("How many Plants you want be harvested?"); Console.Write("> "); int qty = Int32.Parse(Console.ReadLine()); j = 1; List <IResource> selectedType = new List <IResource> (); foreach (var currentPlantGroup in groupedPlants) { if (j == inputType) { foreach (var selectedPlant in currentPlantGroup) { if (selectedType.Count < qty) { selectedType.Add(selectedPlant); } else { break; } } } j++; } ; Console.WriteLine(selectedType.Count); if (field <= farm.NaturalFields.Count) { SunFlower sunny = new SunFlower(); if (qty == 1) { farm.NaturalFields[field - 1].RemoveResource(farm, selectedType[0]); Console.WriteLine($"Total seeds Harvested: {sunny.Process(Equipment)}"); } else { farm.NaturalFields[field - 1].RemoveResource(farm, selectedType); Console.WriteLine($"Total seeds Harvested: {sunny.Process(Equipment)}"); } } else { if (selectedType[0].Type == "SunFlower") { SunFlower sunny = new SunFlower(); if (qty == 1) { farm.PlowedFields[field - farm.NaturalFields.Count - 1].RemoveResource(farm, selectedType[0]); Console.WriteLine($"Total seeds Harvested: {sunny.Process(Equipment)}"); } } else { Sesame sesamy = new Sesame(); if (qty == 1) { farm.PlowedFields[field - farm.NaturalFields.Count - 1].RemoveResource(farm, selectedType[0]); Console.WriteLine($"Total seeds Harvested: {sesamy.Process(Equipment)}"); } } } } // if (qty >= 1) { // farm.NaturalFields[field].RemoveResource (farm, selectedType); // } // } else { // Console.WriteLine ("The following animals are in the chicken house:"); // var groupedAnimals = farm.ChickenHouses[choice - farm.GrazingFields.Count - 1].Resources.GroupBy ( // currentAnimal => currentAnimal.Type // ); // var i = 1; // foreach (var currentAnimalGroup in groupedAnimals) { // Console.WriteLine ($"{i}. {currentAnimalGroup.Count() + " " + currentAnimalGroup.Key}"); // i++; // }; // Console.WriteLine (); // Console.WriteLine ("Which resource should be processed?"); // Console.Write ("> "); // int input = Int32.Parse (Console.ReadLine ()); // } } catch (FormatException) { } } }
// Methods public double Process(SeedHarvester x) { return(_seedsProduced); }
public static void CollectInput(Farm farm, SeedHarvester seedHarvester) { var answer = ""; do { Utils.Clear(); var filterPlowedField = farm.PlowedFields.Where(field => field.PlantsInFacility() > 0).ToList(); if (filterPlowedField.Count > 0) { for (int i = 0; i < filterPlowedField.Count; i++) { Console.WriteLine($"{i + 1}. Plowed Field ({filterPlowedField[i].PlantsInFacility()} Plant(s) in the fields)"); filterPlowedField[i].PlantsGroups(); } Console.WriteLine(); // How can I output the type of plant chosen here? Console.WriteLine($"What field to harvest?"); Console.Write("> "); int choice = Int32.Parse(Console.ReadLine()); Utils.Clear(); Console.Write("Heres a list of plants in your chosen field"); Console.WriteLine(); var plantsInFacility = filterPlowedField[choice - 1]._plants; var selectedFacilityGroup = plantsInFacility.GroupBy(g => g.Type).ToList(); /*foreach (var plant in selectedFacilityGroup) * { * Console.WriteLine($"This field has {plant.Count()} {plant.Key}(s)"); * }*/ for (int i = 0; i < selectedFacilityGroup.Count; i++) { Console.WriteLine($"{i+1}. {selectedFacilityGroup[i].Key} ({selectedFacilityGroup[i].Count()})"); } Console.WriteLine(); // How can I output the type of plant chosen here? Console.WriteLine($"What plant to process?"); Console.Write("> "); int plantChoice = Int32.Parse(Console.ReadLine()); plantChoice--; Console.WriteLine($"How many plants to process?"); Console.Write("> "); int plantNumber = Int32.Parse(Console.ReadLine()); if ((seedHarvester.GetFreeCapacity() >= plantNumber) && (selectedFacilityGroup[plantChoice].Count() >= plantNumber)) { for (int i = 0; i < plantNumber; i++) { Console.WriteLine(selectedFacilityGroup[plantChoice].Last().ToString()); seedHarvester.AddResource(selectedFacilityGroup[plantChoice].Last()); plantsInFacility.Remove(plantsInFacility.Last(p => p.Type == selectedFacilityGroup[plantChoice].Key)); } Console.WriteLine("Do you want to add more? Y/N"); answer = Console.ReadLine(); } else { Console.WriteLine("Incorrect input (capacity or plants number). Processing current resource."); Console.ReadLine(); answer = "N"; } } else { Console.WriteLine("no plants in field, processing everything in harvester"); Console.ReadLine(); answer = "N"; } } while (answer.ToUpper() == "Y"); seedHarvester.Process(farm); Console.ReadLine(); //plantsInFacility[plantChoice].Harvest(); /* * Couldn't get this to work. Can you? * Stretch goal. Only if the app is fully functional. */ // farm.PurchaseResource<IPlowed>(plant, choice); }