/// <summary> /// Check if the collection of castles has more than 0 elements. /// </summary> /// <param name="castleInfoSize">The size of the castle info collection</param> /// <returns>True if the collection has zero elements false if there are elements.</returns> public static bool CheckEmptyCastleCollection(int castleInfoSize) { bool bHasNoElements = castleInfoSize < 1; if (bHasNoElements) { ConsoleDisplay.ErrorNoCastlesToDisplay(); } return(bHasNoElements); }
/// <summary> /// Loop on the name castle display until a valid name is given. /// </summary> /// <returns>The new name of the castle.</returns> public static string UserInputNewCastleName() { string name = ""; do { ConsoleDisplay.DisplayNameCastle(); name = Console.ReadLine(); } while (name.Equals("")); return(name); }
/// <summary> /// Loop until an accurate price is read. /// </summary> /// <returns>The new price of the castle.</returns> public static int UserInputNewPrice() { int price = 0; do { ConsoleDisplay.DisplayPriceOfCastle(); price = ConsoleUtil.TryUserInputConvert(Console.ReadLine()); } while (price <= 0); return(price); }
/// <summary> /// Attempt to convert the users input from a string into /// an integer 32. /// </summary> /// <param name="userInput">The user input to convert to an integer</param> /// <returns>The userInput converted into an integer if the userInput is valid.</returns> public static int TryUserInputConvert(string userInput) { int answer; try { answer = Convert.ToInt32(userInput); } catch (FormatException) { ConsoleDisplay.ErrorIncorrectInput(); answer = 0; } return(answer); }