Exemplo n.º 1
0
        // Shows the given input length, coloring each letter green (correct) or red (incorrect).
        private void SetAnalyzedNameTextBox(String input)
        {
            Animal currentAnimal = animalSpelling.GetCurrentAnimal();

            analyzedNameTextBlock.Inlines.Clear();
            if (currentAnimal == null)
            {
                return;
            }

            UpdatePrompt();

            VerifiedLetterCollection collection = animalSpelling.VerifyInput(input, currentAnimal.getAnimalName());

            foreach (VerifiedLetter letter in collection.letters)
            {
                Media.Color color;
                if (letter.isCorrect)
                {
                    color = Colors.Green;
                }
                else
                {
                    color = Colors.Red;
                }

                analyzedNameTextBlock.Inlines.Add(animalSpelling.CreateRun(letter.letter, color));
            }
        }
Exemplo n.º 2
0
 // Constructs a new result from an animal and user input string and adds it to the results queue
 public void AddResult(Animal animal, VerifiedLetterCollection verifiedInput)
 {
     if (animal != null && verifiedInput != null)
     {
         results.Enqueue(new SpellingResult(animal, verifiedInput));
     }
 }
        // Builds a formatted textBlock from formatted text
        private Border BuildFormattedBlock(VerifiedLetterCollection text)
        {
            // Build the textBlock
            TextBlock formattedTextBlock = new TextBlock();

            formattedTextBlock.FontSize   = textFontSize;
            formattedTextBlock.FontFamily = font;
            foreach (VerifiedLetter letter in text.letters)
            {
                Media.Color color;
                if (letter.isCorrect)
                {
                    color = Colors.Green;
                }
                else
                {
                    color = Colors.Red;
                }

                formattedTextBlock.Inlines.Add(AnimalSpelling.Instance.CreateRun(letter.letter, color));
            }

            // Build the border
            Border formattedTextBorder = new Border();

            formattedTextBorder.Width = textBorderWidth;
            formattedTextBorder.Child = formattedTextBlock;

            return(formattedTextBorder);
        }
Exemplo n.º 4
0
        // Sets the next animal based on a random animal index. No animal in the animal set
        // is reapeted. Once the set of remaining animals is empty, sets the current animal
        // to null.
        public Animal NextAnimal(String input)
        {
            VerifiedLetterCollection verifiedInput = VerifyInput(input, GetCurrentAnimal().getAnimalName());

            // add the current input to results
            results.AddResult(GetCurrentAnimal(), verifiedInput);

            if (allAnimalsUsed)
            {
                currentIndex = -1;
            }

            if (currentIndex > -1 && currentIndex < animals.getSize())
            {
                // set the current animal used
                animals.setUsed(animalIndexes[++currentIndex]);
            }

            return(GetCurrentAnimal());
        }
Exemplo n.º 5
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);
        }
        // Builds a formatted textBlock from formatted text
        private Border BuildFormattedBlock(VerifiedLetterCollection text)
        {
            // Build the textBlock
            TextBlock formattedTextBlock = new TextBlock();
            formattedTextBlock.FontSize = textFontSize;
            formattedTextBlock.FontFamily = font;
            foreach (VerifiedLetter letter in text.letters)
            {
                Media.Color color;
                if (letter.isCorrect)
                    color = Colors.Green;
                else
                    color = Colors.Red;

                formattedTextBlock.Inlines.Add(AnimalSpelling.Instance.CreateRun(letter.letter, color));
            }

            // Build the border
            Border formattedTextBorder = new Border();
            formattedTextBorder.Width = textBorderWidth;
            formattedTextBorder.Child = formattedTextBlock;

            return formattedTextBorder;
        }
Exemplo n.º 7
0
 // Constructor takes the animal, the input string, and whether or not the result is correct
 public SpellingResult(Animal animal, VerifiedLetterCollection verifiedInput)
 {
     this.animal = animal;
     this.verifiedInput = verifiedInput;
     this.isCorrect = verifiedInput.isCorrect;
 }
 // Constructs a new result from an animal and user input string and adds it to the results queue
 public void AddResult(Animal animal, VerifiedLetterCollection verifiedInput)
 {
     if (animal != null && verifiedInput != null)
         results.Enqueue(new SpellingResult(animal, verifiedInput));
 }
Exemplo n.º 9
0
 // Constructor takes the animal, the input string, and whether or not the result is correct
 public SpellingResult(Animal animal, VerifiedLetterCollection verifiedInput)
 {
     this.animal        = animal;
     this.verifiedInput = verifiedInput;
     this.isCorrect     = verifiedInput.isCorrect;
 }
Exemplo n.º 10
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;
        }