private static string validateUserGuess(string userInput) { userInput = userInput.ToLower(); InvalidInputError error = null; bool valid = false; do { if (userInput.Length != 1) { if (userInput.Length == 0)//checking if the input is empty { error = new InvalidInputError(InvalidInputError.ErrorTypes.EmptyInput); } else if (userInput.Length > 1)//checking if the input is Multi Letters { error = new InvalidInputError(InvalidInputError.ErrorTypes.ReceivedStringExpectedChar); } Console.Write($"\n{error.ErrorMessage}"); valid = false; Console.Write("\nEnter a letter: "); userInput = Console.ReadLine(); } else { valid = true; } }while (!valid); return(userInput); }
/// <summary> /// A method to prompt to the user that the input is invalid if an empty string is entered as a puzzle solution /// </summary> public static string PromptInValidEmptyInputAsPuzzleSolution() { InvalidInputError error = new InvalidInputError(InvalidInputError.ErrorTypes.EmptyInput); Console.Write($"\n{error.ErrorMessage}"); Console.Write("\nPlease enter a valid solution to the puzzle: "); string puzzleSolution = Console.ReadLine().ToLower(); return(puzzleSolution); }
/// <summary> /// A method to ask user for the type of action they will take /// <returns>char of '1' or '2' to indicate solving or guessing a letter</returns> /// </summary> public static int GetActionType() { Console.Write("Please enter 1 to solve the puzzle or enter 2 to guess a letter: "); string answer = Console.ReadLine(); while (answer != "1" && answer != "2") { InvalidInputError error = new InvalidInputError(InvalidInputError.ErrorTypes.InvalidInput1Or2); Console.WriteLine($"\n{error.ErrorMessage}"); Console.Write("\nPlease enter 1 to solve the puzzle or enter 2 to guess a letter: "); answer = Console.ReadLine(); } return((int)Char.GetNumericValue(answer[0])); }
/// <summary> /// A method to ask if another player will be added to game /// <returns>char of 'y' or 'n' to indicate if another player will be added</returns> /// </summary> public static char AddAdditionalPlayer() { Console.Write("\nWould you like to add an additional player? (y/n): "); string answer = Console.ReadLine(); while (answer.ToLower() != "y" && answer.ToLower() != "n") { InvalidInputError error = new InvalidInputError(InvalidInputError.ErrorTypes.InvalidInputYOrN); Console.WriteLine($"\n{error.ErrorMessage}"); Console.Write("Would you like to add an additional player? (y/n): "); answer = Console.ReadLine(); } return(answer.ToLower()[0]); }
/// <summary> /// A method to get a new player's name /// <returns>string name of player</returns> /// </summary> public static string CreatePlayer() { Console.Write("\nWhat should we call you?: "); string name = Console.ReadLine(); while (string.IsNullOrEmpty(name)) { InvalidInputError error = new InvalidInputError(InvalidInputError.ErrorTypes.EmptyInput); Console.WriteLine($"\n{error.ErrorMessage}"); Console.Write("Vanna White would like to know your name. \nPlease input your name once more so we can play the game!: "); name = Console.ReadLine(); } Console.WriteLine($"\nWelcome to the game {name}!"); return(name); }