コード例 #1
0
        public void RunLevel()
        {
            string        characters = wordOperator.Shuffle(wordOperator.GivingRandomWordWithNLenght(Int32.Parse(chosenLevel)));
            List <string> soutions   = wordOperator.FindingSoutions(characters);

            PrintLevelStartingPoint(characters);
            string attempt = reader.ReadNewLine();

            while (true)
            {
                if (attempt == CommandConstants.SURRENDER_COMMAND)
                {
                    writer.PrintOnNewLine(MenuMessages.wordsLeft);
                    soutions.ForEach(x => writer.PrintOnNewLine("->" + x));
                    break;
                }
                if (attempt == CommandConstants.CLEAR_COMMAND)
                {
                    PrintLevelStartingPoint(characters);
                    attempt = reader.ReadNewLine();
                    continue;
                }
                if (attempt != null && !wordOperator.AtemptValidation(characters.Trim(), attempt.Trim()))
                {
                    writer.PrintOnNewLine(MenuMessages.invalidInput);
                    attempt = reader.ReadNewLine();
                    continue;
                }
                if (trieFromDictionary.Search(attempt))
                {
                    soutions.Remove(attempt);
                    writer.PrintOnNewLine(attempt + @" is valid word!");
                    player.Score += attempt.Length;
                    writer.PrintOnNewLine(soutions.Count + " words left.");
                }
                else
                {
                    writer.PrintOnNewLine(attempt + " is not valid word!");
                }
                if (soutions.Count == 0)
                {
                    writer.PrintOnNewLine(MenuMessages.wordsSolved);
                    break;
                }
                attempt = reader.ReadNewLine();
            }
        }
コード例 #2
0
 public bool Validate(string text)
 {
     return(_validWords.Search(text));
 }
コード例 #3
0
        private void Search(ITrie trie, string s, bool expected)
        {
            bool result = trie.Search(s);

            Assert.AreEqual(expected, result);
        }