public static void CollectInput(Farm farm, string seedChoice, int amountChoice) { Console.Clear(); PlowedField anyFieldWithRoom = farm.PlowedFields.Find(pf => (pf.MaxCapacity - pf.CurrentCapacity) >= amountChoice); if (anyFieldWithRoom != null) { for (int i = 0; i < farm.PlowedFields.Count; i++) { PlowedField currentField = farm.PlowedFields[i]; if (currentField.MaxCapacity - currentField.CurrentCapacity >= amountChoice) { Console.WriteLine($"{i + 1}. Plowed field - {currentField.CurrentCapacity} of {currentField.MaxCapacity} rows of plants\n"); } } Console.WriteLine(); // How can I output the type of plant chosen here? if (UserTriedToSelectAFullFacility) { Console.WriteLine("That field does not have enough room."); } Console.WriteLine($"Place the plants where?"); Console.Write("> "); int choice = Int32.Parse(Console.ReadLine()) - 1; //user is buying multiple seeds so we need a list holding however many they want, then adding the list of resources to field which is on the farm List <ISeedProducing> plants = new List <ISeedProducing>(); //determine which type of plant they want and then with for loop adding the appropriate amount(amountChoice parameter) to list of plants for (int i = 0; i < amountChoice; i++) { plants.Add(new Sesame()); } //now we're adding the list of plants to the specific field that the user chose from the menu farm.PlowedFields[choice].AddResource(farm, plants); /* * Couldn't get this to work. Can you? * Stretch goal. Only if the app is fully functional. */ // farm.PurchaseResource<IGrazing>(animal, choice); } //else if there isn't room for all the plants the user is trying to add, this else statement notifies user and takes to previous menu else { PurchaseSeed.ThereIsNoRoomForTheSeedBeingPurchased = true; Program.DisplayBanner(); PurchaseSeed.CollectInput(farm); } }
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(); try { if (int.Parse(choice) <= 3 && int.Parse(choice) >= 1) { switch (Int32.Parse(choice)) { case 1: ChoosePlowedField.CollectInput(farm, new Sesame()); break; case 2: ChooseSunflowerField <Sunflower> .CollectInput(farm, new Sunflower()); break; case 3: ChooseNaturalField.CollectInput(farm, new Wildflower()); break; default: Console.WriteLine("Invalid option. Redirecting to main menu."); Thread.Sleep(2000); break; } } else { Console.WriteLine("Invalid option. Please try again."); Thread.Sleep(2000); DisplayBanner(); PurchaseSeed.CollectInput(farm); } } catch (FormatException) { Console.WriteLine("Invalid option. Please try again."); Thread.Sleep(2000); DisplayBanner(); PurchaseSeed.CollectInput(farm); } }
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"); } }
public static void CollectInput(Farm farm, IPlowed plant) { Console.Clear(); List <IFacility <IPlowed> > openPlowedFields = new List <IFacility <IPlowed> >(); var sortedPlowedFields = farm.PlowedFields.Where(plowedField => (plowedField.Capacity - 1) >= plowedField.CurrentStock()).ToList(); for (int i = 0; i < sortedPlowedFields.Count; i++) { if ((sortedPlowedFields[i].Capacity - 1) >= sortedPlowedFields[i].CurrentStock()) { openPlowedFields.Add(sortedPlowedFields[i]); Console.WriteLine($"{i + 1}. Plowed Field (Current Stock: {sortedPlowedFields[i].CurrentStock()})"); sortedPlowedFields[i].ShowPlantsByType(); } } Console.WriteLine(); if (sortedPlowedFields.Count > 0) { Console.WriteLine($"Place the plant where?"); Console.Write("> "); try { int choice = Int32.Parse(Console.ReadLine()); if (plant is IPlowed) { try { sortedPlowedFields[choice - 1].AddResource(plant); } catch (ArgumentOutOfRangeException) { Console.WriteLine("Invalid option. Please create a new plant and try again."); Thread.Sleep(2000); DisplayBanner(); PurchaseSeed.CollectInput(farm); } } else { Console.WriteLine("There are no matching facilities available. Please create one first."); Thread.Sleep(2000); } } catch (FormatException) { Console.WriteLine("Invalid option. Please create a new plant and try again."); Thread.Sleep(2000); DisplayBanner(); PurchaseSeed.CollectInput(farm); } } // if (openPlowedFields.Count > 0) // { // Console.WriteLine($"Place the plant where?"); // Console.Write("> "); // int choice = Int32.Parse(Console.ReadLine()); // if (plant is IPlowed) // { // sortedPlowedFields[choice - 1].AddResource(plant); // } // else // { // // Console.Clear(); // Console.WriteLine("Please select another facility"); // for (int i = 0; i < farm.PlowedFields.Count; i++) // { // Console.WriteLine($"{i + 1}. Plowed Field"); // } // } // } // else // { // Console.WriteLine("There are no matching facilities available. Please create one first."); // Thread.Sleep(2000); // } /* * Couldn't get this to work. Can you? * Stretch goal. Only if the app is fully functional. */ // farm.PurchaseResource<IGrazing>(animal, choice); }
public static void CollectInput(Farm farm, TPlantType plant) { Console.Clear(); Dictionary <int, IPlantField> plantFieldDictionary = new Dictionary <int, IPlantField>(); var sortedPlowedFields = farm.PlowedFields.Where(plowedField => (plowedField.Capacity - 1) >= plowedField.CurrentStock()).ToList(); var sortedNaturalFields = farm.NaturalFields.Where(naturalField => (naturalField.Capacity - 1) >= naturalField.CurrentStock()).ToList(); for (int i = 0; i < sortedPlowedFields.Count; i++) { if ((sortedPlowedFields[i].Capacity - 1) >= sortedPlowedFields[i].CurrentStock()) { plantFieldDictionary.Add(i + 1, sortedPlowedFields[i]); Console.WriteLine($"{i + 1}. Plowed Field (Current Stock: {sortedPlowedFields[i].CurrentStock()})"); sortedPlowedFields[i].ShowPlantsByType(); } } for (int i = 0; i < sortedNaturalFields.Count; i++) { if ((sortedNaturalFields[i].Capacity - 1) >= sortedNaturalFields[i].CurrentStock()) { plantFieldDictionary.Add(i + sortedPlowedFields.Count + 1, sortedNaturalFields[i]); Console.WriteLine($"{i + sortedPlowedFields.Count + 1}. Natural Field (Current Stock: {sortedNaturalFields[i].CurrentStock()})"); sortedNaturalFields[i].ShowPlantsByType(); } } Console.WriteLine(); if (plantFieldDictionary.Count > 0) { Console.WriteLine($"Place the plant where?"); Console.Write("> "); try { int choice = Int32.Parse(Console.ReadLine()); // Take user's choice and search for the dictionary key that matches the integer. Return the type of the chosen field. string chosenField = plantFieldDictionary[choice].Type; if (chosenField == "Plowed Field") { try { sortedPlowedFields[choice - 1].AddResource(plant); } catch (KeyNotFoundException) { Console.WriteLine("Invalid option. Please create a new plant and try again."); Thread.Sleep(2000); DisplayBanner(); PurchaseSeed.CollectInput(farm); } } else if (chosenField == "Natural Field") { try { sortedNaturalFields[choice - sortedPlowedFields.Count - 1].AddResource(plant); } catch (KeyNotFoundException) { Console.WriteLine("Invalid option. Please create a new plant and try again."); Thread.Sleep(2000); DisplayBanner(); PurchaseSeed.CollectInput(farm); } } else { Console.WriteLine("Please select another facility"); Thread.Sleep(2000); } } catch (FormatException) { Console.WriteLine("Invalid option. Please create a new plant and try again."); Thread.Sleep(2000); DisplayBanner(); PurchaseSeed.CollectInput(farm); } catch (KeyNotFoundException) { Console.WriteLine("Invalid option. Please create a new plant and try again."); Thread.Sleep(2000); DisplayBanner(); PurchaseSeed.CollectInput(farm); } } else { Console.WriteLine("There are no matching facilities available. Please create one first."); Thread.Sleep(2000); } }
public static void CollectInput(Farm farm, string seedChoice, int amountChoice) { Console.Clear(); // //anything that is of type object can be put in this list // List<object> sunflowerFields = new List<object>(); // farm.PlowedFields.ForEach(pf => { // //cast from type PlowedField to type object // object transformedField = pf as object; // sunflowerFields.Add(transformedField); // }); // farm.NaturalFields.ForEach(nf => { // //cast from type PlowedField to type object // object transformedField = nf as object; // sunflowerFields.Add(transformedField); // }); NaturalField anyNaturalFieldWithRoom = farm.NaturalFields.Find(nf => (nf.MaxCapacity - nf.CurrentCapacity) >= amountChoice); PlowedField anyPlowedFieldWithRoom = farm.PlowedFields.Find(pf => (pf.MaxCapacity - pf.CurrentCapacity) >= amountChoice); if (anyNaturalFieldWithRoom != null || anyPlowedFieldWithRoom != null) { for (int i = 0; i < farm.NaturalFields.Count; i++) { NaturalField currentField = farm.NaturalFields[i]; if (currentField.MaxCapacity - currentField.CurrentCapacity >= amountChoice) { Console.WriteLine($"{i + 1}. Natural field - {currentField.CurrentCapacity} of {currentField.MaxCapacity} rows of plants\n"); } } for (int i = 0; i < farm.PlowedFields.Count; i++) { PlowedField currentField = farm.PlowedFields[i]; //this allows the plowed fields to be displayed after the available natural fields if (currentField.MaxCapacity - currentField.CurrentCapacity >= amountChoice) { Console.WriteLine($"{i + farm.NaturalFields.Count + 1}. Plowed field - {currentField.CurrentCapacity} of {currentField.MaxCapacity} rows of plants\n"); } } Console.WriteLine(); // How can I output the type of plant chosen here? if (UserTriedToSelectAFullFacility) { Console.WriteLine("That field does not have enough room."); } Console.WriteLine($"Place the plants where?"); Console.Write("> "); int choice = Int32.Parse(Console.ReadLine()); //user is buying multiple seeds so we need a list holding however many they want, then adding the list of resources to field which is on the farm //if their choice is a number greater than Natural Fields count, then they are choosing a plowed field if (choice > farm.NaturalFields.Count) { List <ISeedProducing> plants = new List <ISeedProducing>(); //determine which type of plant they want and then with for loop adding the appropriate amount(amountChoice parameter) to list of plants for (int i = 0; i < amountChoice; i++) { plants.Add(new Sunflower()); } //now we're adding the list of plants to the specific field that the user chose from the menu //choice(user input) - farm.NaturalFields.Count (number of natural fields listed) - 1 (bc index starts from 0 not 1) PlowedField target = farm.PlowedFields[choice - farm.NaturalFields.Count - 1]; if (target.MaxCapacity - target.CurrentCapacity >= amountChoice) { farm.PlowedFields[choice - 1 - farm.NaturalFields.Count].AddResource(farm, plants); ChooseSunflowerField.UserTriedToSelectAFullFacility = false; } else { UserTriedToSelectAFullFacility = true; ChooseSunflowerField.CollectInput(farm, seedChoice, amountChoice); } //make sure that this variable is set to false, in case user was previous directed PurchaseSeed.ThereIsNoRoomForTheSeedBeingPurchased = false; } else { List <ICompostProducing> plants = new List <ICompostProducing>(); //determine which type of plant they want and then with for loop adding the appropriate amount(amountChoice parameter) to list of plants NaturalField target = farm.NaturalFields[choice - 1]; if (target.MaxCapacity - target.CurrentCapacity >= amountChoice) { for (int i = 0; i < amountChoice; i++) { plants.Add(new Sunflower()); } //now we're adding the list of plants to the specific field that the user chose from the menu //choice(user input) - 1 (bc index starts from 0 not 1) target.AddResource(farm, plants); //make sure that this variable is set to false, in case user was previous directed PurchaseSeed.ThereIsNoRoomForTheSeedBeingPurchased = false; UserTriedToSelectAFullFacility = false; } else { UserTriedToSelectAFullFacility = true; ChooseSunflowerField.CollectInput(farm, seedChoice, amountChoice); } } /* * Couldn't get this to work. Can you? * Stretch goal. Only if the app is fully functional. */ // farm.PurchaseResource<IGrazing>(animal, choice); } //else if there isn't room for all the plants the user is trying to add, this else statement notifies user and takes to previous menu else { PurchaseSeed.ThereIsNoRoomForTheSeedBeingPurchased = true; Program.DisplayBanner(); PurchaseSeed.CollectInput(farm); } }