private bool checkValidInputFormat(string i_InputFromUser) { bool validFormat = true; string inputWithoutSpaces = i_InputFromUser.Replace(" ", string.Empty); if (inputWithoutSpaces.Length == 4) { foreach (char currentLetter in inputWithoutSpaces) { if ((currentLetter < 'A' || currentLetter > 'Z') && (currentLetter != '\b')) { validFormat = false; Board.WriteLine("Wrong format please choose Capitals letter"); break; } } } else { Board.WriteLine(string.Format("Please enter only {0} letters", r_LengthOfGuess)); validFormat = false; } return(validFormat); }
private bool checkValidInputContext(string i_InputFromUser) { string inputWithoutSpaces = i_InputFromUser.Replace(" ", string.Empty); bool validContext = true; foreach (char currentLetter in inputWithoutSpaces) { if (currentLetter < 'A' || currentLetter > 'H') { validContext = false; Board.WriteLine("Wrong context , please enter only letters between A and H"); break; } } return(validContext); }
private void validGuessNumber(out int o_NumberOfGuesses) { bool isValid = false; o_NumberOfGuesses = 0; Board.WriteLine("Please enter valid guess numbers"); while (!isValid) { bool isANumber = int.TryParse(Board.ReadLine(), out o_NumberOfGuesses); if (isANumber) { if (o_NumberOfGuesses >= 4 && o_NumberOfGuesses <= 10) { isValid = true; break; } } Board.WriteLine("This is not a valid input, please enter a number between 4-10"); } Board.WriteLine(string.Format("{0} is a valid input ", o_NumberOfGuesses)); }
public void Run() { Ex02.ConsoleUtils.Screen.Clear(); Board.PrintBoard(null, r_LengthOfGuess, m_NumberOfTotalGuesses); m_GameResult = eGameResult.StillPlaying; while (m_NumOfLeftGuesses > 0) { string verifiedInputString = VerifyInputFromUser(); if (verifiedInputString.Equals("Q")) { m_GameResult = eGameResult.Abort; break; } eGuessLetter[] currentGuess = getVerifyInputFromUser(verifiedInputString); Turn currentTurn = new Turn(m_ComputerAnswer, currentGuess); int cellToAddCurrentTurn = m_NumberOfTotalGuesses - m_NumOfLeftGuesses; m_TurnArray[cellToAddCurrentTurn] = currentTurn; Ex02.ConsoleUtils.Screen.Clear(); Board.PrintBoard(m_TurnArray, r_LengthOfGuess, m_NumberOfTotalGuesses); if (currentTurn.IsCorrect()) { m_GameResult = eGameResult.Win; break; } m_NumOfLeftGuesses--; } if (m_NumOfLeftGuesses == 0) { m_GameResult = eGameResult.Loss; Board.WriteLine(string.Format("The real soultion was {0} , sorry maybe next time.", m_ComputerAnswerStringFormat)); } }