private void setErrorTextColor(int starting, int ending, RichTextBox rtb)
        {
            //Select the entire box
            rtb.SelectAll();
            //Create a selection
            TextSelection currentSelection = rtb.Selection;
            //Set the starter pointer to the start of the content
            TextPointer start    = rtb.Document.ContentStart;
            TypingModel newModel = new TypingModel();
            //Indicate the start and end pos
            TextPointer startPos = GetTextPointAt(start, starting);
            TextPointer endPos   = GetTextPointAt(start, ending);

            //Choose the area in which to change the color
            currentSelection.Select(startPos, endPos);
            Color color = (Color)ColorConverter.ConvertFromString("#Ab3334");

            currentSelection.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(color));
            currentSelection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
        }
        //Set the color for the next word
        private int setNextIndex(int nextIndex)
        {
            int returnIndex = 0;

            if (roundNumber == 0)
            {
                TypingModel newModel = new TypingModel();
                //Gets the total count of words
                paragraphString = newModel.getTextInArray();;
                //Gets the length of the first word
                int currentLength = paragraphString[0].Length;
                returnIndex = 0 + currentLength + 1;
            }
            else
            {
                TypingModel newModel = new TypingModel();
                paragraphString = newModel.getTextInArray();
                int currentLength = paragraphString[roundNumber].Length;
                returnIndex = currentIndex + currentLength + 1;
            }
            return(returnIndex);
        }
        private double calAverageTypingSpeed(TimeSpan elapsed, List <int> numberOfCorrectKeyInput, List <int> numberOfWrongKeyInput)
        {
            //Takes the total time
            double time = elapsed.TotalMinutes + elapsed.TotalSeconds;

            Console.WriteLine("Current Elapsed Time is " + time);
            int totalInput = 0;

            //Gets all the input regardless of correct or wrong
            foreach (int input in numberOfCorrectKeyInput)
            {
                totalInput += input;
            }
            foreach (int input in numberOfWrongKeyInput)
            {
                totalInput += input;
            }

            //Find the percentage that got wrong
            TypingModel newModel = new TypingModel();

            string[] totalCount = newModel.getTextInArray();
            //Get the total number of word count
            int    totalWords   = totalCount.Count();
            double currentError = currentErrorList.Count();
            //Get the percentage of Wrong
            double percentageOfWrong = currentError / totalWords;

            Console.WriteLine("Current number of error is " + currentErrorList.Count);
            Console.WriteLine("Current total count is " + totalCount.Count());
            Console.WriteLine("Current percentage of wrong is " + percentageOfWrong);

            //Calculate the Total * (100 - Percentage of Wrong)
            //Which is basically the rate at which is quite average
            double finalInput         = totalInput * (1 - percentageOfWrong);
            double averageTypingSpeed = finalInput / time;

            return(averageTypingSpeed);
        }
        private void keyboardFunctions(object sender, KeyEventArgs e)
        {
            //If this is the first round, i will start the timer once one of the key is inputted
            if (roundNumber == 0 && startTimerBoolean == false)
            {
                startTimer();
            }
            //If user enters the space key
            if (e.Key == Key.Space)
            {
                Console.WriteLine("Activated ");
                //Check to see if this is the last word in the entire set of words
                if (roundNumber == paragraphString.Length - 1)
                {
                    //Checks if its correct or wrong
                    if (enterField.Text.Equals(paragraphString[roundNumber]) || enterField.Text.Equals(" " + paragraphString[roundNumber]))
                    {
                        //If correct, then save the correct word, set the color and add it into the correct list
                        startCorrectKeyCapture(enterField.Text.Length);
                        setCorrectTextColor(currentIndex, nextIndex, paragraphBox);
                        currentCorrectList.Add(currentIndex);
                        nextCorrectList.Add(nextIndex);
                        enterField.Text = "";
                    }
                    else
                    {
                        //save the wrong word, set the wrong color and add it into the wrong list
                        startWrongKeyCapture(enterField.Text.Length);
                        setErrorTextColor(currentIndex, nextIndex, paragraphBox);
                        currentErrorList.Add(currentIndex);
                        nextErrorList.Add(nextIndex);
                        enterField.Text = "";
                    }

                    nextIndex = setNextIndex(nextIndex);
                    //removeTextColor(paragraphBox);
                    // setCorrect(currentCorrectList, nextCorrectList, paragraphBox);
                    //if (currentErrorList.Count != 0)
                    //{
                    //    setError(currentErrorList, nextErrorList, paragraphBox);
                    //}

                    //This is what happens after you finish
                    TypingModel newModel = new TypingModel();
                    //Get the total number of word count
                    string [] totalCount = newModel.getTextInArray();
                    //Check to see if the word count matches
                    if (nextErrorList.Count() + nextCorrectList.Count() == totalCount.Count())
                    {
                        //If it matches, check the validation of this page to true
                        CurrentPageModel.sixthValidation = true;
                        //A big chuck of stuff that shows the average of your typing speed
                        MessageBox.Show("You have successfully completed the Typing Test");
                        Console.WriteLine("Number of Errors are " + nextErrorList.Count());
                        Console.WriteLine("Number of Corrects are " + nextCorrectList.Count());
                        double averageTypingSpeed = calAverageTypingSpeed(sw.Elapsed, numberOfCorrectKeyInput, numberOfWrongKeyInput);
                        MessageBox.Show("Number of Errors are " + nextErrorList.Count() + "\n" +
                                        "Number of Corrects are " + nextCorrectList.Count() + "\n" +
                                        "The Average Character Per Second is " + averageTypingSpeed + "\n" +
                                        "The Average Number of Words per minute is " + ((averageTypingSpeed * 60) / 5));
                        Console.WriteLine(
                            "Number of Errors are " + nextErrorList.Count() + "\n" +
                            "Number of Corrects are " + nextCorrectList.Count() + "\n" +
                            "The Average Character Per Second is " + averageTypingSpeed + "\n" +
                            "The Average Number of Words per minute is " + ((averageTypingSpeed * 60) / 5));
                        stopGame();
                    }
                }
                else
                {
                    if (enterField.Text.Equals(paragraphString[roundNumber]) || enterField.Text.Equals(" " + paragraphString[roundNumber]))
                    {
                        //If correct, then save the correct word, set the color and add it into the correct list
                        Console.Write("Hiuhsada");
                        startCorrectKeyCapture(enterField.Text.Length);
                        //Increment the current round to the next
                        roundNumber++;
                        currentCorrectList.Add(currentIndex);
                        nextCorrectList.Add(nextIndex);
                        //setCorrectTextColor(current)
                        setCorrectTextColor(currentIndex, nextIndex, paragraphBox);
                        //Set the current index to the next location and set the next index to the next next location
                        currentIndex = nextIndex;
                        nextIndex    = setNextIndex(nextIndex);
                        //removeTextColor(paragraphBox);
                        //if (currentErrorList.Count != 0)
                        //{
                        //    setError(currentErrorList, nextErrorList, paragraphBox);
                        //}
                        setNextTextColor(currentIndex, nextIndex, paragraphBox);
                        enterField.Text = "";
                    }
                    else
                    {
                        //save the wrong word, set the wrong color and add it into the wrong list
                        roundNumber++;
                        currentErrorList.Add(currentIndex);
                        startWrongKeyCapture(enterField.Text.Length);
                        nextErrorList.Add(nextIndex);
                        //removeTextColor(paragraphBox);
                        //if (currentCorrectList.Count != 0)
                        //{
                        //    setCorrect(currentCorrectList, nextCorrectList, paragraphBox);
                        //}
                        //setError(currentErrorList, nextErrorList, paragraphBox);
                        setErrorTextColor(currentIndex, nextIndex, paragraphBox);
                        //Set the current index to the next location and set the next index to the next next location
                        currentIndex = nextIndex;
                        nextIndex    = setNextIndex(nextIndex);
                        setNextTextColor(currentIndex, nextIndex, paragraphBox);
                        enterField.Text = "";
                    }
                }
            }
        }
        public async Task UserTyping(TypingModel model)
        {
            var user = await _userManager.GetUserAsync(User);

            await _hubContext.Clients.All.SendAsync("IsTyping", user.UserName, model.IsTyping);
        }