public static void CollectInput(Farm farm) { Console.WriteLine("1. Cow"); Console.WriteLine("2. Ostrich"); Console.WriteLine("3. Duck"); Console.WriteLine("4. Pig"); Console.WriteLine("5. Goat"); Console.WriteLine("6. Chicken"); Console.WriteLine("7. Sheep"); Console.WriteLine(); Console.WriteLine("What are you buying today?"); Console.Write("> "); string choice = Console.ReadLine(); switch (Int32.Parse(choice)) { case 1: ChooseGrazingField.CollectInput(farm, new Cow()); break; case 2: ChooseGrazingField.CollectInput(farm, new Ostrich()); break; case 3: ChooseDuckHouse.CollectInput(farm, new Duck()); break; case 4: ChooseGrazingField.CollectInput(farm, new Pig()); break; case 5: ChooseGrazingField.CollectInput(farm, new Goat()); break; case 6: ChooseChickenHouse.CollectInput(farm, new Chicken()); break; case 7: ChooseGrazingField.CollectInput(farm, new Sheep()); break; default: Console.Clear(); Console.Write("Not a valid option. Press enter to try again"); Console.ReadLine(); Console.Clear(); PurchaseStock.CollectInput(farm); break; } }
public static void CollectInput(Farm farm, IGrazing animal) { Console.Clear(); GrazingField anyFieldWithRoom = farm.GrazingFields.Find(gf => gf.CurrentCapacity < gf.MaxCapacity); if (anyFieldWithRoom != null) { for (int i = 0; i < farm.GrazingFields.Count; i++) { GrazingField currentField = farm.GrazingFields[i]; if (currentField.CurrentCapacity < currentField.MaxCapacity) { Console.WriteLine($"{i + 1}. Grazing field - {currentField.CurrentCapacity} of {currentField.MaxCapacity} animals\n"); } } Console.WriteLine(); // How can I output the type of animal chosen here? if (UserTriedToSelectAFullFacility) { Console.WriteLine("That facility is already full."); } Console.WriteLine($"Place the animal where?"); Console.Write("> "); int choice = Int32.Parse(Console.ReadLine()) - 1; farm.GrazingFields[choice].AddResource(farm, animal); PurchaseStock.ThereIsNoRoomForTheAnimalBeingPurchased = false; } else { PurchaseStock.ThereIsNoRoomForTheAnimalBeingPurchased = true; Program.DisplayBanner(); PurchaseStock.CollectInput(farm); } /* * 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, Chicken chicken) { Console.Clear(); ChickenHouse anyHouseWithRoom = farm.ChickenHouses.Find(ch => ch.CurrentCapacity < ch.MaxCapacity); if (anyHouseWithRoom != null) { for (int i = 0; i < farm.ChickenHouses.Count; i++) { ChickenHouse currentHouse = farm.ChickenHouses[i]; if (currentHouse.CurrentCapacity < currentHouse.MaxCapacity) { Console.WriteLine($"{i + 1}. {currentHouse}"); } } Console.WriteLine(); // How can I output the type of plant chosen here? if (UserTriedToSelectAFullFacility) { Console.WriteLine("That facility is already full."); } Console.WriteLine($"Place the Chicken where?"); Console.Write("> "); int choice = Int32.Parse(Console.ReadLine()) - 1; farm.ChickenHouses[choice].AddResource(farm, chicken); } else { PurchaseStock.ThereIsNoRoomForTheAnimalBeingPurchased = true; Program.DisplayBanner(); PurchaseStock.CollectInput(farm); } /* * 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) { Console.WriteLine("1. Cow"); Console.WriteLine("2. Ostrich"); Console.WriteLine("3. Goat"); Console.WriteLine("4. Sheep"); Console.WriteLine("5. Pig"); Console.WriteLine("6. Chicken"); Console.WriteLine("7. Duck"); Console.WriteLine(); Console.WriteLine("What are you buying today?"); Console.Write("> "); string choice = Console.ReadLine(); try { switch (Int32.Parse(choice)) { case 1: if (farm.GrazingFields.Count >= 1) { ChooseGrazingField.CollectInput(farm, new Cow()); } else { Console.Clear(); System.Console.WriteLine("You haven't created a facility for this animal yet."); CreateFacility.CollectInput(farm); } break; case 2: if (farm.GrazingFields.Count >= 1) { ChooseGrazingField.CollectInput(farm, new Ostrich()); } else { Console.Clear(); System.Console.WriteLine("You haven't created a facility for this animal yet."); CreateFacility.CollectInput(farm); } break; case 3: if (farm.GrazingFields.Count >= 1) { ChooseGrazingField.CollectInput(farm, new Goat()); } else { Console.Clear(); System.Console.WriteLine("You haven't created a facility for this animal yet."); CreateFacility.CollectInput(farm); } break; case 4: if (farm.GrazingFields.Count >= 1) { ChooseGrazingField.CollectInput(farm, new Sheep()); } else { Console.Clear(); System.Console.WriteLine("You haven't created a facility for this animal yet."); CreateFacility.CollectInput(farm); } break; case 5: if (farm.GrazingFields.Count >= 1) { ChooseGrazingField.CollectInput(farm, new Pig()); } else { Console.Clear(); System.Console.WriteLine("You haven't created a facility for this animal yet."); CreateFacility.CollectInput(farm); } break; case 6: if (farm.ChickenHouses.Count >= 1) { ChooseChickenHouse.CollectInput(farm, new Chicken()); } else { Console.Clear(); System.Console.WriteLine("You haven't created a facility for this animal yet."); CreateFacility.CollectInput(farm); } break; case 7: if (farm.DuckHouses.Count >= 1) { ChooseDuckHouse.CollectInput(farm, new Duck()); } else { Console.Clear(); System.Console.WriteLine("You haven't created a facility for this animal yet."); CreateFacility.CollectInput(farm); } break; default: break; } } catch (FormatException) { Console.Clear(); Console.WriteLine(); Console.WriteLine(@" _ _ _ _ ____ _ _ / |__| |--| [__] |--|. _ -=(') ;; // // : '.---.__ | --_-_)__) `.____,' \ \ ___\ \ ( \ \ - There's been an Ost-glitch / "); Console.WriteLine(); Console.WriteLine("Please select an available stock option"); PurchaseStock.CollectInput(farm); } }