/// <summary> /// Reset mNextLetter and mCurrentWord to their default values. /// </summary> private void ResetWord() { if (!mCurrentWord.IsDisposed) { mCurrentWord.ResetPaint(); } mNextLetter = Word.NO_LETTER; mCurrentWord = null; }
/// <summary> /// Keyboard pressed event. /// </summary> private void frmMain_KeyPress(object sender, KeyPressEventArgs e) { if (!timerTimeKeeping.Enabled) { return; } // Key matches the next letter needed - paint that letter. if (e.KeyChar == mNextLetter) { mNextLetter = mCurrentWord.PaintLetter(Color.Red); // Word completed if (mNextLetter == Word.NO_LETTER) { IncrementLabel(lblScore); ResetWord(); } } // No given word - search for a word that the given key matches its first letter. else if (mCurrentWord == null) { mCurrentWord = CheckFirstLetterOfAllWords(e.KeyChar); if (mCurrentWord == null) { IncrementLabel(lblMistakes); } else { mNextLetter = mCurrentWord.PaintLetter(Color.Red); } } // Key doesn't match the correct letter - reset the word. else { ResetWord(); IncrementLabel(lblMistakes); } }
/// <summary> /// Generate a new Word control and place it on the grid. /// </summary> private void GenerateNewWord() { var w = new Word(); w.Text = NextWord(); var location= NextLocation(); w.BackColor = BackColor; if (location == NULL) { StopGame(); MessageBox.Show(this, "Game Over"); } else { grid.Controls.Add(w, location.X, location.Y); } }