private bool TryToSwitchToNiceHangman() { if (PossibleWordsBank.Count == 1) { NiceHangmanGame = new HangmanGame(PossibleWordsBank.First()); NiceHangmanGame.Start(); return(true); } return(false); }
/// <summary> /// Processes the guess. /// </summary> /// <param name="guess">Guess.</param> public void ProcessGuess(string guess) { if (NiceHangmanGame != null) { NiceHangmanGame.ProcessGuess(guess); return; } if (!IsGuessProcessable(guess)) { return; } if (TryToSwitchToNiceHangman()) { // I reprocess the guess to let NiceHangman come in this.ProcessGuess(guess); return; } string wordSaved = this.PossibleWordsBank.Last(); // Maybe pick randomly and check that is different from guess? this.PossibleWordsBank.RemoveAll(word => { // I remove all the words that have same char at same position for (int i = 0; i < guess.Length; i++) { if (word.Contains(guess[i])) { return(true); } } return(false); }); if (PossibleWordsBank.Count == 0) { // I have removed all the words, I reuse the saved one PossibleWordsBank.Add(wordSaved); ProcessGuess(guess); } }