internal bool PlayGuess(string guess) { bool isItAGoodGuess = false; for (int i = 0; i < MysteryWord.Length; i++) { if (MysteryWord[i] == guess[0]) { CurrentGuess[i * 2] = guess[0]; isItAGoodGuess = true; PreviousGuesses.Add(guess[0]); } } if (!isItAGoodGuess) { CurrentTry++; } return(isItAGoodGuess); }
public void Guess(char guessChar) { // TODO: Consider using Ardalis.GuardClauses // TODO: Consider returning Ardalis.Result if (char.IsWhiteSpace(guessChar)) { throw new InvalidGuessException("Guess cannot be blank."); } if (!Regex.IsMatch(guessChar.ToString(), "^[A-Z]$")) { throw new InvalidGuessException("Guess must be a capital letter A through Z"); } if (IsOver) { throw new InvalidGuessException("Can't make guesses after game is over."); } if (PreviousGuesses.Any(g => g == guessChar)) { throw new DuplicateGuessException(); } PreviousGuesses.Add(guessChar); if (_secretWord.IndexOf(guessChar) >= 0) { if (!CurrentMaskedWord.Contains(_maskChar)) { Result = GameResult.Won; } return; } if (GuessesRemaining <= 0) { Result = GameResult.Lost; } }