public static bool CorrectLetter(char letter) { string secretWordTrimmed = SecretWord.Trim(); string[] splitWord = secretWordTrimmed.Split(); if (FullWord.Contains(letter)) { for (int i = 0; i <= FullWord.Length - 1; i++) { if (FullWord[i] == letter) { splitWord[i] = letter.ToString(); } } SecretWord = string.Join(" ", splitWord); IsCorrectLetter = true; if (!SecretWord.Contains('_')) { GameWon = true; return(GameWon); } return(IsCorrectLetter); } else { IsCorrectLetter = false; CountGuesses++; return(IsCorrectLetter); } }
public void PickLetter(char c) { if (RemainingAttempts < 1) { throw new InvalidOperationException($"You cannot pick any more letter as you have no more remaining attempts"); } if (RemainingSecretLetters.Count < 1) { throw new InvalidOperationException($"You cannot pick any more letter as there are no remaining letters"); } UsedLetters.Add(c); var upperChar = char.ToUpper(c); if (SecretWord.Contains(upperChar)) { RemainingSecretLetters.Remove(upperChar); } else { RemainingAttempts--; } }
public void CorrectGuess() { if (!SecretWord.Contains(GuessLetters.LastOrDefault())) { Guesses--; } }
public Result <string> Guess(char g) { if (!validCharacters.Contains(g)) { return(Result.Failure <string>("Invalid Guess")); } if (IncorrectGuesses.Contains(g) || CorrectGuesses.Contains(g)) { return(Result.Failure <string>("Duplicate Guess")); } if (!SecretWord.Contains(g)) { IncorrectGuesses.Add(g); return(Result.Failure <string>("Incorrect Guess")); } CorrectGuesses.Add(g); GameStateSecretWord = GameStateSecretWord.Replace(g.ToString(), ""); if (string.IsNullOrWhiteSpace(GameStateSecretWord)) { return(Result.Success("Game won!!!")); } return(Result.Success("Correct Guess")); }
private bool IsCorrectGuess(string guess) { if (SecretWord.Contains(guess)) { return(true); } else { return(false); } }