Ejemplo n.º 1
0
        private void checkButton_Click(object sender, EventArgs e)
        {
            if (checkButton.Text.Equals("New"))
            {
                this.Controls.Clear();
                this.InitializeComponent();
                _equation            = new Equation();
                equationTextBox.Text = _equation.Text;
                answerTextBox.Focus();
            }
            else
            {
                var parsed = int.TryParse(answerTextBox.Text, out var answer);

                if (parsed)
                {
                    _equation.MakeAttempt(answer);

                    if (_equation.IsCorrect)
                    {
                        answerTextBox.BackColor = Color.Chartreuse;
                        checkButton.Text        = "New";
                        _log?.WriteLog(_equation.Statistics());
                    }
                    else
                    {
                        answerTextBox.BackColor = Color.Crimson;
                        answerTextBox.Text      = string.Empty;
                    }
                }
                else
                {
                    MessageBox.Show($"What number is {answerTextBox.Text}?", "Huh?", MessageBoxButtons.OK, MessageBoxIcon.Question);
                }
            }
        }
Ejemplo n.º 2
0
 private void mainForm_Load(object sender, EventArgs e)
 {
     _equation            = new Equation();
     equationTextBox.Text = _equation.Text;
 }