Hello. I write the application "guess the word." I found video tutorials and make them. Code next

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; namespace finalHome { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string word = ""; List<Label> labels = new List<Label>(); int t = 10; private void timer1_Tick(object sender, EventArgs e) { t--; timer.Text = t.ToString(); if (t == 0) { timer1.Stop(); MessageBox.Show("Your time is up the word was "+ word,"LOST"); Reset(); } } private void startButton_Click(object sender, EventArgs e) { Reset(); timer1.Enabled = true; } public void MakeLabels() { word = GetRandomWord(); char[] chars = word.ToCharArray(); int between = 330 / chars.Length; for (int i = 0; i < chars.Length; i++) { labels.Add(new Label()); labels[i].Location = new Point((i * between) + 10, 80); labels[i].Text = "_"; labels[i].Parent = groupBox1; labels[i].BringToFront(); labels[i].CreateControl(); } attemptLabel2.Text = (chars.Length).ToString(); } void Mistake() { for (int i = word.Length; i > 0; i--) { attemptLabel2.Text = (word.Length-1).ToString(); } } string GetRandomWord() { WebClient wc = new WebClient(); string wordList = wc.DownloadString("http://www-cs-faculty.stanford.edu/~knuth/sgb-words.txt"); string[] words = wordList.Split('\n'); Random ran = new Random(); return words[ran.Next(0, words.Length )]; } public void submitButton_Click(object sender, EventArgs e) { char letter = SubmitTextox.Text.ToLower().ToCharArray()[0]; if(!char.IsLetter(letter)) { MessageBox.Show("you can submit only letters","Error", MessageBoxButtons.OK,MessageBoxIcon.Error); return; } if (word.Contains(letter)) { char[] letters = word.ToCharArray(); for (int i = 0; i < letters.Length; i++) { if (letters[i] == letter) labels[i].Text = letter.ToString(); } foreach (Label l in labels) if (l.Text == "_") return; MessageBox.Show("You won!", "Nice"); Reset(); } else { MessageBox.Show("there is not this letter in the word!","Error"); label1.Text += " " + letter.ToString() + ","; Mistake(); } } void Reset() { GetRandomWord(); MakeLabels(); label1.Text = "Missed"; SubmitTextox.Text = ""; timer1.Enabled = false; timer1.Enabled = true; } private void resetButton_Click(object sender, EventArgs e) { Reset(); } private void submitWord_Click(object sender, EventArgs e) { if (WordTextBox.Text == word) { MessageBox.Show("You have won! The word is " + word); Reset(); } else { MessageBox.Show("Wrong word! Try again"); } } } } 

1 If the timer value is 0, a message is displayed that the user has lost. When you click on reset, the timer continues to count to -1 -2 -3 and so on. How to make it so that when you click on the Reset timer starts the report with an initial value? 2. How to make that when entering incorrect letters or words in SubmitTextOx and WordTextBox respectively, the value of attemptLabel2 is decreased by one. and when this value reaches 0, a message was also issued that the user lost. Thank you very much

Closed due to the fact that off-topic participants αλεχολυτ , pavel , Denis Bubnov , Vadim Ovchinnikov , Ruslan_K January 18, '17 at 5:14 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - αλεχολυτ, pavel, Denis Bubnov, Vadim Ovchinnikov, Ruslan_K
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    1. To understand how to reset the timer, look carefully at the code, and find the variable that stores the remaining time. Hint, the value of this variable is displayed in the MessageBox when the timer ticks. - Uranus
  • one
    2. Store the number of attempts in a variable of type int, and output its value in attemptLabel2 every time the number of attempts changes. - Uranus
  • And what is your timer1 ? - VladD

1 answer 1

 void Reset() { t = 10; GetRandomWord(); MakeLabels(); label1.Text = "Missed"; SubmitTextox.Text = ""; timer1.Enabled = false; timer1.Enabled = true; }