public void keyboard_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == richTextBox1.Text[0]) { temp.Push(richTextBox1.Text[0]); richTextBox1.Text = richTextBox1.Text.Remove(0, 1); activeColor = Color.Yellow; stats.Update(true); } else { wrong++; stats.Update(false); activeColor = Color.Red; if (displayMsg.Text != "" && e.KeyChar != Convert.ToChar(Keys.Back)) { displayMsg.Text = displayMsg.Text.Remove(0, 1); } } if (e.KeyChar == Convert.ToChar(Keys.Back) && temp.Count != 0) { richTextBox1.Text = richTextBox1.Text.Insert(0, Convert.ToString(temp.Pop())); } if (e.KeyChar == Convert.ToChar(Keys.Menu) || e.KeyChar == Convert.ToChar(Keys.Tab) || e.KeyChar == Convert.ToChar(Keys.ControlKey) || e.KeyChar == Convert.ToChar(Keys.Enter) || e.KeyChar == Convert.ToChar(Keys.Escape) || e.KeyChar == Convert.ToChar(Keys.Back)) { wrong--; activeColor = Color.Yellow; } if (richTextBox1.Text == "") { richTextBox1.Text = GetRandomWord(); displayMsg.Text = ""; correct++; TimeLeft.Stop(); TimeLeft.Start(); } CorrectLbl.Text = "Correct: " + correct; WrongLbl.Text = "Health: " + (20 - wrong); AccuracyLbl.Text = "Accuracy: " + stats.Accuracy + "%"; }
private void Resume(object sender, EventArgs e) { timer1.Start(); TimeLeft.Start(); }