Esempio n. 1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            Button start = (Button)sender;

            if (!start.Text.Contains("Over"))
            {
                start.Text           = "Start Over!";
                tbDifficulty.Enabled = false;
                groupBox1.Enabled    = true;
                RandomNumberGenerator generator = new RandomNumberGenerator(1, _maxNumber, 5);
                List <int>            numbers   = new List <int>();
                ModifyProgressBarColor.SetState(pbTrials, 1);
                _actualNumber = generator.Generate();
                for (int i = 1; i <= _maxNumber; i++)
                {
                    numbers.Add(i);
                }
                cbInput.DataSource = numbers;
                groupBox1.Text     = "Started...";
            }
            else
            {
                Reset();
                lblResult.Visible = false;
            }
        }
Esempio n. 2
0
        /*
         *  review: The method names are not according to the agreed standards
         *  underscore operator should not be used to decalre the method
         */
        private void btnOk_Click(object sender, EventArgs e)
        {
            lblResult.Visible = true;
            if (_numberOfTries >= 5)
            {
                MessageBox.Show("To try again, click start over!", "You Lost!");
                lblResult.Text = "Sorry, you have exceeded the allowed number of tries!";
                return;
            }
            int    input  = 0;
            string result = "Sorry! Wrong Guess!";

            if (int.TryParse(cbInput.Text, out input))
            {
                result = new CompareInputs().IsTheSame(input, _actualNumber);
                if (result.Contains("Success"))
                {
                    MessageBox.Show("You guessed right!", "Congratulations!");
                    var wordEnd = _numberOfTries == 0 ? "y" : "ies";
                    lblResult.Text      = $"You guessed right in {_numberOfTries + 1} tr{ wordEnd}!{Environment.NewLine}And you won {((_maxNumber / 5) * (5 - _numberOfTries))}$";
                    lblResult.ForeColor = Color.Green;
                    Reset();
                    return;
                }
            }
            lblResult.Text = result;
            _numberOfTries++;
            lblPrize.Text = ((_maxNumber / 5) * (5 - _numberOfTries)).ToString();
            pbTrials.PerformStep();

            ModifyProgressBarColor.SetState(pbTrials, _numberOfTries == 1 ? 1 : _numberOfTries < 4 ? 3 : 2);
            if (_numberOfTries >= 5)
            {
                MessageBox.Show("To try again, click start over!", "You Lost!");
                lblResult.Text = "Sorry, you have exceeded the allowed number of tries!";
                return;
            }
        }