Exemplo n.º 1
0
        /// <summary>
        /// Function starting letter check on correctness.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonClic(object sender, EventArgs e)
        {
            // By pressing the button its colour is changed.
            ActiveControl.BackColor = Color.DarkRed;

            //Receive value of a letter
            z = ActiveControl.Text;
            int count = 0;

            // We betray a letter in сласс Game.
            g.Letter = Convert.ToChar(z);

            // We start letter check.
            g.Start();
            conc = g.conclusion;

            // We remove a fur-tree letter the correct has been pressed.
            foreach (char el in conc)
                {
                this.Controls["label" + (count + 1).ToString()].Text = conc[count].ToString();
                count++;
                }

            // We remove the transition button on следуюшее a word.
            if (Game.CorrectLettersCounter==g.conclusion.Length && Game.RightWordsCounter+errorCount<=5)
                {
                for (int i = 2; i < 28; i++)
                    {
                    this.Controls["button" + (i).ToString()].Enabled = false;
                    }
                label15.Text = "You guessed a word";
                button28.Visible = true;
                }

            //We remove a gallows picture if there was press an incorrect letter.
            if (g.WrongLettersCounter != 0)
                {
                pictureBox1.Image = Image.FromFile(@"Resources\" + g.WrongLettersCounter + ".jpg");
                }

            if (g.WrongLettersCounter == 0)
                {
                pictureBox1.Image = null;
                }
            if (g.WrongLettersCounter == 7 )
                {
                count = 0;
                errorCount++;
                g.WrongLettersCounter = 0;
                if (Convert.ToInt32(complexity) == 1 && errorCount <= 4)
                    {
                    g.conclusion = g.Words[Convert.ToInt32(g.random[g.index])].ToCharArray();
                    conc = g.conclusion;

                    // We remove a fur-tree letter the correct has been pressed.
                    foreach (char el in conc)
                        {
                        this.Controls["label" + (count + 1).ToString()].Text = conc[count].ToString();
                        count++;
                        }

                    for (int i = 2; i < 28; i++)
                        {
                        this.Controls["button" + (i).ToString()].Enabled = false;
                        }
                    label15.Text = "You did not guess a word";
                    button28.Visible = true;
                    }

                if (Convert.ToInt32(complexity) == 2 && errorCount <= 2)
                    {
                    g.conclusion = g.Words[Convert.ToInt32(g.random[g.index])].ToCharArray();
                    conc = g.conclusion;

                    // We remove a fur-tree letter the correct has been pressed.
                    foreach (char el in conc)
                        {
                        this.Controls["label" + (count + 1).ToString()].Text = conc[count].ToString();
                        count++;
                        }

                    for (int i = 2; i < 28; i++)
                        {
                        this.Controls["button" + (i).ToString()].Enabled = false;
                        }
                    label15.Text = "You did not guess a word";
                    button28.Visible = true;
                    }

                if ((Convert.ToInt32(complexity) == 2 && errorCount > 2) || (Convert.ToInt32(complexity) == 1 && errorCount > 4) || (Convert.ToInt32(complexity) == 3))
                    {
                    label15.Text = "You did not guess a word";
                    Form6 f6 = new Form6();
                    f6.Opacity = 0;
                    f6.Show();
                    for (int i = 0; i <= 100; i++)
                        {
                        f6.Opacity = i / 100.0;
                        System.Threading.Thread.Sleep(1);//чем меньше число, тем быстрее появится
                        }
                    this.Hide();
                    g.WinCounter = 0;
                    g.WrongLettersCounter = 0;
                    Game.RightWordsCounter = 0;
                    Game.CorrectLettersCounter = 0;
                    for (int i = 2; i < 28; i++)
                        {
                        this.Controls["button" + (i).ToString()].Enabled = false;
                        }
                    }
                }

            label13.Text = "Amount of the guessed words: " + (Game.RightWordsCounter).ToString();
            label14.Text = "Amount of not guessed words: " + errorCount.ToString();
            ActiveControl.Enabled = false;
            button29.Enabled=true;
            button1.Enabled = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Function starting letter check on correctness.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonClic(object sender, EventArgs e)
            {
            // By pressing the button its colour is changed.
            ActiveControl.BackColor = Color.Red;

            //Receive value of a letter
            z = ActiveControl.Text;
            int count = 0;

            // We betray a letter in сласс Game.
            g.Letter = Convert.ToChar(z);

            // We start letter check.
            g.Start();
            conc = g.conclusion;

            // We remove a fur-tree letter the correct has been pressed.
            foreach (char el in conc)
                {
                this.Controls["label" + (count + 1).ToString()].Text = conc[count].ToString();
                count++;
                }

            // We remove the transition button on следуюшее a word.
            if (Game.RightWordsCounter > g.LastNumberCounter)
                {
                for (int i = 2; i < 28; i++)
                    {
                    this.Controls["button" + (i).ToString()].Enabled = false;
                    }
                button28.Visible = true;
                }

            //We remove a gallows picture if there was нажта an incorrect letter.
            pictureBox1.Image = Image.FromFile(@"Resources\" + g.WrongLettersCounter + ".jpg");

            if (g.WrongLettersCounter == 7 )
                {
                count = 0;
                errorCount++;
                g.WrongLettersCounter = 0;
                if (Convert.ToInt32(complexity) == 1 && errorCount <= 4)
                    {
                    g.conclusion = Game.words[Convert.ToInt32(g.random[Game.RightWordsCounter])].ToCharArray();
                    conc = g.conclusion;

                    // We remove a fur-tree letter the correct has been pressed.
                    foreach (char el in conc)
                        {
                        this.Controls["label" + (count + 1).ToString()].Text = conc[count].ToString();
                        count++;
                        }

                    for (int i = 2; i < 28; i++)
                        {
                        this.Controls["button" + (i).ToString()].Enabled = false;
                        }

                    button28.Visible = true;
                    }

                if (Convert.ToInt32(complexity) == 2 && errorCount <= 2)
                    {
                    g.conclusion = Game.words[Convert.ToInt32(g.random[Game.RightWordsCounter])].ToCharArray();
                    conc = g.conclusion;

                    // We remove a fur-tree letter the correct has been pressed.
                    foreach (char el in conc)
                        {
                        this.Controls["label" + (count + 1).ToString()].Text = conc[count].ToString();
                        count++;
                        }

                    
                    for (int i = 2; i < 28; i++)
                        {
                        this.Controls["button" + (i).ToString()].Enabled = false;
                        }

                    button28.Visible = true;
                    }

                if ((Convert.ToInt32(complexity) == 2 && errorCount > 2) || (Convert.ToInt32(complexity) == 1 && errorCount > 4) || (Convert.ToInt32(complexity) == 3))
                    {
                    Form6 f6 = new Form6();
                    this.Hide();
                    f6.Show();
                    g.WinCounter = 0;
                    g.WrongLettersCounter = 0;
                    Game.RightWordsCounter = 0;
                    for (int i = 2; i < 28; i++)
                        {
                        this.Controls["button" + (i).ToString()].Enabled = false;
                        }
                    }
                }
            if (Game.RightWordsCounter > errorCount && (Game.RightWordsCounter - errorCount)!=0 )
                {
                label13.Text = "Guess words: " + (Game.RightWordsCounter - errorCount).ToString();
                }
            if (Game.RightWordsCounter == 0 || Game.RightWordsCounter < errorCount)
                {
                label13.Text = "Guess words: 0";
                }
            label14.Text = "Not guess the word: " + errorCount.ToString();
            ActiveControl.Enabled = false;
            button1.Enabled = true;
            }