Exemplo n.º 1
0
        public VerifiedLetterCollection VerifyInput(String userInput, String expectedInput)
        {
            VerifiedLetterCollection collection = new VerifiedLetterCollection();

            collection.isCorrect = true;

            for (int i = 0; i < userInput.Length; i++)
            {
                VerifiedLetter verifiedLetter = new VerifiedLetter();

                // Set the letter upper case if its first, otherwise lower case
                if (i == 0)
                {
                    verifiedLetter.letter = Char.ToUpper(userInput[i]);
                }
                else
                {
                    verifiedLetter.letter = Char.ToLower(userInput[i]);
                }

                // set isCorrect
                verifiedLetter.isCorrect = Char.ToLower(userInput[i]) == Char.ToLower(expectedInput[i]);
                if (!verifiedLetter.isCorrect)
                {
                    collection.isCorrect = false;
                }

                collection.letters.Add(verifiedLetter);
            }

            // Adds the number of missing characters as stars.
            for (int i = userInput.Length; i < expectedInput.Length; i++)
            {
                VerifiedLetter missingLetter = new VerifiedLetter();
                missingLetter.letter    = '*';
                missingLetter.isCorrect = false;
                collection.letters.Add(missingLetter);
                collection.isCorrect = false;
            }
            return(collection);
        }
Exemplo n.º 2
0
        public VerifiedLetterCollection VerifyInput(String userInput, String expectedInput)
        {
            VerifiedLetterCollection collection = new VerifiedLetterCollection();
            collection.isCorrect = true;

            for (int i = 0; i < userInput.Length; i++)
            {
                VerifiedLetter verifiedLetter = new VerifiedLetter();

                // Set the letter upper case if its first, otherwise lower case
                if (i == 0)
                    verifiedLetter.letter = Char.ToUpper(userInput[i]);
                else
                    verifiedLetter.letter = Char.ToLower(userInput[i]);

                // set isCorrect
                verifiedLetter.isCorrect = Char.ToLower(userInput[i]) == Char.ToLower(expectedInput[i]);
                if (!verifiedLetter.isCorrect)
                    collection.isCorrect = false;

                collection.letters.Add(verifiedLetter);
            }

            // Adds the number of missing characters as stars.
            for (int i = userInput.Length; i < expectedInput.Length; i++)
            {
                VerifiedLetter missingLetter = new VerifiedLetter();
                missingLetter.letter = '*';
                missingLetter.isCorrect = false;
                collection.letters.Add(missingLetter);
                collection.isCorrect = false;
            }
            return collection;
        }