private async void Timer_TickAsync(object sender, EventArgs e) { if (rate < 1) { timer.Stop(); return; } switch (counter) { case 1: star1.Visibility = Visibility.Visible; break; case 2: star2.Visibility = Visibility.Visible; break; case 3: star3.Visibility = Visibility.Visible; break; case 4: star4.Visibility = Visibility.Visible; break; case 5: star5.Visibility = Visibility.Visible; break; } if (counter >= rate) { timer.Stop(); return; } await Task.Delay(150); TypingSounds.PlayCoinSound(); counter++; }
/// <summary> /// Appends text entered to the input tab. /// </summary> /// <param name="text"></param> internal void Append(string text) { TypingSounds.PlayTypingSound(); //Perfom backspacing if the user presses backspace. if (text == "\b") { if (AllowBackspace) { index = runs.Count - 1; if (runs.Count > 0) { tblInput.Inlines.Remove(runs[index]); runs.RemoveAt(index); } } } else if (text == "\r") { return; } else { //Check for index bounds if (string.IsNullOrWhiteSpace(ComparisonText) || ComparisonText.Length == runs.Count) { return; } Run run = new Run { Foreground = new SolidColorBrush(new Color { A = animatedBrush.Color.A, B = animatedBrush.Color.B, R = animatedBrush.Color.R, G = animatedBrush.Color.G }), Text = text }; if (errorIndexs.Contains(index)) { run.Foreground = correctedBrush; } if (text != ComparisonText[runs.Count].ToString()) { TypingSounds.PlayErrorSound(); run.Foreground = Brushes.Red; errorIndexs.Add(index); if (text == " ") { run.Text = "_"; } MisMatchCount++; EntireMisMatchCount++; } runs.Add(run); tblInput.Inlines.Add(run); Strokes++; EnteredText = text; } fromWithin = true; EntryText = tblInput.Text; fromWithin = false; index = runs.Count; if (outRuns.Count > index) { outRuns[index].Background = brush; } try { outRuns[index - 1].Background = Brushes.Transparent; } catch { } PlaceOnCenter(); Progress = ((double)EntryText.Length / ComparisonText.Length) * 100; if (Progress == 100) { TypingSounds.PlayFinishSound(); } animatedBrush.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation); }