/// <summary> /// Validates the user's input and checks if there were any previous that were the same. /// </summary> /// <param name="storedInputs">List of successful inputs</param> /// <returns></returns> private char GetUserLetter(List <char> storedInputs) { char userInput; for (; ;) { //Get input, method already validates if it's a letter input userInput = InputValidation.ValidateLetter(LetterCase.Upper); //Cause user to input again if current input matches any previous inputs if (InputValidation.CheckAlreadyUsedInput(storedInputs, userInput)) { Console.WriteLine("You've alredy chosen this Letter!\nPlease enter a letter"); } //Successful input else { return(userInput); } } }
/// <summary> /// GetUserInput(); /// Gets valid input from user to use to uncover a slot in the grid. /// /// Arguments: /// -A list of previous valid inputs to compare if the same option is chosen again. /// -A table that translates the input to a value /// /// Steps: /// -Try get user to input a row. /// -Try get user to input a column. /// -Convert both inputs into a key. /// -Use key to get an output from the table. /// -If the output has already been chosen before then repeat from the first step. /// </summary> private int GetUserInput(List <int> previousInputs, Dictionary <string, int> table) { int temp; char[] input = new char[2]; for (; ;) { Console.WriteLine("\nPick A row"); input[(int)GridSelection.Row] = InputValidation.ValidateInput(1, 3).ToString()[0]; Console.WriteLine("\nPick A column"); input[(int)GridSelection.Column] = InputValidation.ValidateInput(1, 3).ToString()[0]; if (table.TryGetValue(new string(input), out temp) && !InputValidation.CheckAlreadyUsedInput(previousInputs, temp)) { return(temp); } else { Console.WriteLine("You've already chosen this slot"); } } }
/// <summary> /// GenerateCpuNumbers() /// Generates a specified amount of numbers and stores each digit into an array index. /// Each digit is between 1-9 and is unique. /// /// Arguments: /// -The amount of numbers the computer wil generate. /// /// Steps: /// -Create array of specified size. /// -Iterate through the array. /// -Randomly generate a number between 1 - 9 /// -If the generated number has already been used, then generate a new number. /// -Else the number is assigned into that element of the array. /// -Return array when finished iterating. /// </summary> /// <param name="inputArraySize">Will return array of the size</param> /// <returns></returns> private char[] GenerateCpuNumbers(int inputArraySize) { char[] temp = new char[inputArraySize]; char generatedChar; List <char> storedNumbers = new List <char>(); for (int i = 0; i < temp.Length; i++) { for (; ;) { generatedChar = random.Next(1, 10).ToString().ToCharArray()[0]; if (!InputValidation.CheckAlreadyUsedInput <char>(storedNumbers, generatedChar)) { storedNumbers.Add(generatedChar); temp[i] = generatedChar; break; } } } return(temp); }