private void textBox2_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (textBox2.Text == "") { MessageBox.Show("Pl, enter a word to be guessed...", "Word missing", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (textBox2.Text == WORD) { WON qe = new WON(); qe.Show(); this.Visible = false; textBox2.Text = ""; } else { MessageBox.Show("your guessed word isn't correct...", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); remaining--; label7.Text = remaining.ToString(); textBox2.Text = ""; value++; draWBodyPart((BodyParts)value); if (value == 9) { remaining = 0; label7.Text = remaining.ToString(); draWBodyPart((BodyParts)value); LOSE l = new LOSE(); l.Show(); this.Visible = false; } } } } }
private void textBox1_KeyDown_1(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (textBox1.Text == "") { MessageBox.Show("Pl, Enter a valid Letter...", "Letter missed...", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { char letter = textBox1.Text.ToLower().ToCharArray()[0]; if (!char.IsLetter(letter)) { MessageBox.Show("U can enter only a letter...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (WORD.Contains(letter)) { char[] Letters = WORD.ToCharArray(); for (int h = 0; h < Letters.Length; h++) { if (Letters[h] == letter) { if (labes[h].Text == letter.ToString()) { MessageBox.Show("U have guessed this letter earlier..", "Repeated", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox1.Text = ""; return; } else { labes[h].Text = letter.ToString(); textBox1.Text = ""; } } } foreach (Label l in labes) { if (l.Text == "__") { return; } } WON w = new WON(); w.Show(); this.Visible = false; //reset(); } else { MessageBox.Show("Letter isn't in the word to be guessed...", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); remaining--; label7.Text = remaining.ToString(); value++; label4.Text += " " + letter.ToString() + ","; draWBodyPart((BodyParts)value); if (value == 9) { draWBodyPart((BodyParts)value); LOSE l = new LOSE(); l.Show(); this.Visible = false; // reset(); } } textBox1.Text = ""; } } }