public static void CollectInput(Farm farm) { Console.WriteLine("1. Grazing field"); Console.WriteLine("2. Plowed field"); Console.WriteLine("3. Duck House"); Console.WriteLine("4. Chicken Coop"); Console.WriteLine("5. Natural Field"); // Add in other facilities Console.WriteLine(); Console.WriteLine("Choose what you want to create"); Console.Write("> "); string input = Console.ReadLine(); switch (Int32.Parse(input)) { case 1: farm.AddGrazingField(new GrazingField()); Console.WriteLine("You created a grazing field! Good Job!"); Thread.Sleep(1000); break; case 2: farm.AddPlowedField(new PlowedField()); Console.WriteLine("You plowed that field! Great job buddy!"); Thread.Sleep(1000); break; case 3: farm.AddDuckHouse(new DuckHouse()); Console.WriteLine("You created a Duck House! Good Job!"); Thread.Sleep(1000); break; case 4: farm.AddChickenCoop(new ChickenCoop()); Console.WriteLine("You built a chicken coop! You're so strong! WOW WOW WOW"); Thread.Sleep(1000); break; case 5: farm.AddNaturalField(new NaturalField()); Console.WriteLine("You built a Natural Field! You're so strong! WOW WOW WOW"); Thread.Sleep(1000); break; default: break; } }
public static void CollectInput(Farm farm) { Console.WriteLine("1. Grazing field"); Console.WriteLine("2. Plowed field"); Console.WriteLine("3. Natural field"); Console.WriteLine("4. Chicken Coop"); Console.WriteLine("5. Duck House"); Console.WriteLine(); Console.WriteLine("Choose what you want to create"); Console.Write("> "); string input = Console.ReadLine(); try { if (int.Parse(input) <= 5 && int.Parse(input) >= 1) { switch (Int32.Parse(input)) { case 1: farm.AddGrazingField(new GrazingField()); break; case 2: farm.AddPlowedField(new PlowedField()); break; case 3: farm.AddNaturalField(new NaturalField()); break; case 4: farm.AddChickenCoop(new ChickenCoop()); break; case 5: farm.AddDuckHouse(new DuckHouse()); 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(); CreateFacility.CollectInput(farm); } } catch (FormatException) { Console.WriteLine("Invalid option. Please try again."); Thread.Sleep(2000); DisplayBanner(); CreateFacility.CollectInput(farm); } }
public static void CollectInput(Farm farm) { Console.WriteLine("1. Grazing field"); Console.WriteLine("2. Plowed field"); Console.WriteLine("3. Natural field"); Console.WriteLine("4. Chicken Coop"); Console.WriteLine("5. Duck House"); Console.WriteLine(); Console.WriteLine("Choose what you want to create"); Console.Write("> "); string input = Console.ReadLine(); //TryParse checks to see if the first param in an int, if not it return false an proceeds to else. If true, out(put) a new var/int called choice if (input != "" && int.TryParse(input, out int choice)) { //now we can use the new variable without having to convert it to an int. switch (choice) { case 1: farm.AddGrazingField(new GrazingField()); Console.Clear(); Console.WriteLine("\n\n\n"); Console.WriteLine("You've created a Grazing Field! Now go'on'n'git'ta'plantin'!"); Console.WriteLine("\n\n"); Console.WriteLine("Press enter to continue"); Console.ReadLine(); break; case 2: farm.AddPlowedField(new PlowedField()); Console.Clear(); Console.WriteLine("\n\n\n"); Console.WriteLine("You've created a Plowed Field! Now go'on'n'git'ta'plantin'!"); Console.WriteLine("\n\n"); Console.WriteLine("Press enter to continue"); Console.ReadLine(); break; case 3: farm.AddNaturalField(new NaturalField()); Console.Clear(); Console.WriteLine("\n\n\n"); Console.WriteLine("You've created a Natural Field! Now go'on'n'git'ta'plantin'!"); Console.WriteLine("\n\n"); Console.WriteLine("Press enter to continue"); Console.ReadLine(); break; case 4: farm.AddChickenCoop(new ChickenCoop()); Console.Clear(); Console.WriteLine("\n\n\n"); Console.WriteLine("You've created a Chicken Coop! You can put a chicken in there!"); Console.WriteLine("\n\n"); Console.WriteLine("Press enter to continue"); Console.ReadLine(); break; case 5: farm.AddDuckHouse(new DuckHouse()); Console.Clear(); Console.WriteLine("\n\n\n"); Console.WriteLine("You've created a Duck House! You can put a Duck in there!"); Console.WriteLine("\n\n"); Console.WriteLine("Press enter to continue"); Console.ReadLine(); break; default: break; } } 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(); } }