public static void CollectInput(Farm farm, ICompostProducing 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.NaturalFields.Count; i++) { // if(i > 0){ Console.WriteLine(farm.NaturalFields[i].Capacity == farm.NaturalFields[i].currentNumberInField ? $"{i + 1}. Natural Field (Full)" : $"{i + 1}. Natural Field ({farm.NaturalFields[i].currentNumberInField} plants)"); } Console.WriteLine(); 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.NaturalFields[choice - 1].currentNumberInField == farm.NaturalFields[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.NaturalFields[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"); } } }
public static void CollectInput(Farm farm, ICompostProducing plant) { Utils.Clear(); //Prints each available natural field for (int i = 0; i < farm.NaturalFields.Count; i++) { try { Console.WriteLine($"{i + 1}. Natural Field ({farm.NaturalFields[i].GetTotal()} plants)"); Console.WriteLine($"{farm.NaturalFields[i].SunflowerCount()} Sunflower"); Console.WriteLine($"{farm.NaturalFields[i].WildflowerCount()} Wildflower"); } catch (Exception) { Console.WriteLine("All fields are full. Please go back to main menu to create a new field!"); Console.WriteLine(); } } Console.WriteLine(); Console.WriteLine($"Which field would you like to choose to plant this seed?"); Console.WriteLine("> "); int choice = Int32.Parse(Console.ReadLine()); // code for full field if (farm.NaturalFields[choice - 1].GetTotal() < farm.NaturalFields[choice - 1].Capacity) { farm.NaturalFields[choice - 1].AddResource(plant); } else { Console.WriteLine("This field is full."); Thread.Sleep(2000); } }
public void ProcessResults(List <IResource> resProcessed) { Dictionary <string, double> compostProduced = new Dictionary <string, double>(); resProcessed.ForEach(composter => { ICompostProducing resource = (ICompostProducing)composter; try { compostProduced.Add(resource.GetType().Name, resource.CollectCompost()); } catch (Exception) { compostProduced[resource.GetType().Name] += resource.CollectCompost(); } }); foreach (KeyValuePair <string, double> composter in compostProduced) { System.Console.WriteLine($"{composter.Value}kg of {composter.Key} compost was collected"); } }
public static void CollectInput(Farm farm, ICompostProducing seed) { Console.Clear(); List <NaturalField> availableNaturalFields = new List <NaturalField>(); for (int i = 0; i < farm.NaturalFields.Count; i++) { if ((farm.NaturalFields[i].Capacity) > farm.NaturalFields[i].GetPlantCount()) { availableNaturalFields.Add(farm.NaturalFields[i]); } } int fieldCount = 1; if (availableNaturalFields.Count == 0) { Console.WriteLine("You do not have any available fields to plant this seed."); Console.ReadLine(); } for (int i = 0; i < availableNaturalFields.Count; i++) { while (fieldCount > 0) { Console.WriteLine($"{i + 1}: This field currently has {availableNaturalFields[i].GetPlantCount()} rows of plants with a capacity of {availableNaturalFields[i].Capacity} rows."); availableNaturalFields[i].getSunflowers(); availableNaturalFields[i].getWildflowers(); 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; availableNaturalFields[realChoice].AddResource(seed); Console.WriteLine($"1 row of plants have been added to this field. You currently have {availableNaturalFields[realChoice].GetPlantCount()} row(s) in this field. Press the 'Enter' key to continue."); fieldCount--; Console.ReadLine(); } } }
public void AddResource(ICompostProducing compost) { compostToProcess.Add(compost); }
public static void CollectInput(Farm farm, ICompostProducing plant) { //Ask the user how many plants they want to 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 <ICompostProducing> manyPlants = Enumerable.Repeat(plant, number).ToList(); Console.Clear(); for (int i = 0; i < farm.NaturalFields.Count; i++) { if (farm.NaturalFields[i].plantCount() == 1) { Console.WriteLine($"{i + 1}. Natural field has ({farm.NaturalFields[i].plantCount()} row of plants)"); } else if (farm.NaturalFields[i].plantCount() < farm.NaturalFields[i].Capacity) { Console.WriteLine($"{i + 1}. Natural field has ({farm.NaturalFields[i].plantCount()} rows of plants)"); } // else // { // Console.WriteLine($"{i + 1}. Natural Field is full. ({farm.NaturalFields[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; // check to see if current plant count plus new list count is less than or equal to capacity. if (farm.NaturalFields[choice].plantCount() + manyPlants.Count() <= farm.NaturalFields[choice].Capacity) { farm.NaturalFields[choice].AddResource(manyPlants); } else { Console.Clear(); Console.WriteLine($@" ~ I'm sorry! That facility can only hold ({farm.NaturalFields[0].Capacity}) plants ~ ************************************************************************ ************** Please choose another facility. **************** ********** If there are no other natural 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 Natural 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 NaturalField and add it to the farm. // go to the ChooseNaturalField menu and pass the plant and farm case 1: farm.AddNaturalField(new NaturalField()); Console.Clear(); Console.WriteLine("Success! One Natural Field Added. Press enter to continue."); Console.ReadLine(); ChooseNaturalField.CollectInput(farm, plant); break; case 2: break; } } }
public static void CollectInput(Farm farm, ICompostProducing compost) { Console.Clear(); for (int i = 0; i < farm.NaturalFields.Count; i++) { if (farm.NaturalFields[i].seedCount() != farm.NaturalFields[i].Capacity) { if (farm.NaturalFields[i].seedCount() > 0) { Console.WriteLine($"{i + 1}. Natural Field ({farm.NaturalFields[i].SeedList()})"); } else { Console.WriteLine($"{i + 1}. Natural Field {farm.NaturalFields[i]}"); } } else { Console.WriteLine($"{i + 1}. Natural Field {farm.NaturalFields[i].shortId()} is at capacity"); } } Console.WriteLine(); Console.WriteLine($"Place the {compost.GetType().Name} which natural field?"); Console.Write("> "); string choice = Console.ReadLine(); if (choice != "" && int.TryParse(choice, out int input)) { int seedCount = farm.NaturalFields[input - 1].seedCount(); if (farm.NaturalFields[input - 1].seedCount() != farm.NaturalFields[input - 1].Capacity) { Console.Clear(); Console.WriteLine("\n\n\n"); farm.NaturalFields[input - 1].AddResource(compost); Console.WriteLine($"Looks like you're the proud owner of a {compost}!"); Console.WriteLine("\n\n"); Console.WriteLine("Press enter to continue"); Console.ReadLine(); } else { Console.Clear(); Console.WriteLine("\n\n\n"); Console.WriteLine($"Natural Field {farm.NaturalFields[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(); } }