public override void Run(WordsRepository repository) { int points; DateTime start, stop; string tentativeAnagram; string randomWord = repository.RandomWord(MIN_NUMBER_OF_ANAGRAMS); UiHandler.WriteMessage(Description); UiHandler.WriteMessage(); UiHandler.WriteMessage("Provide the anagram for the following word:"); UiHandler.WriteMessage(randomWord); start = DateTime.Now; tentativeAnagram = UiHandler.InsertWord(); stop = DateTime.Now; if (repository.IsAnagram(randomWord, tentativeAnagram)) { points = ComputePoints(start, stop); UiHandler.WriteMessage($"You anagrammed the word '{randomWord}' with '{tentativeAnagram}' scoring {points} poits."); } else { UiHandler.WriteMessage($"The provided word '{tentativeAnagram}' is not a valid anagram of '{tentativeAnagram}', so you scored 0 points."); } UiHandler.WriteMessage(); }
public override void Run(WordsRepository repository) { string word; List <string> anagrams; UiHandler.WriteMessage(Description); UiHandler.WriteMessage(); UiHandler.WriteMessage("Please type a word to anagram"); word = UiHandler.InsertWord(); anagrams = repository.ProduceAnagrams(word); if (anagrams.Count() > 0) { if (anagrams.Count() == 1) { UiHandler.WriteMessage("The provided word does not have any anagram..."); } else { foreach (string w in anagrams) { if (!word.Equals(w)) { UiHandler.WriteMessage(w); } } } } else { UiHandler.WriteMessage("Sorry, the chosen word does not exist in the word repository..."); } UiHandler.WriteMessage(); UiHandler.WriteMessage(); }