Beispiel #1
0
        /// <summary>
        /// Срабатывание таймера
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;

            _sumSecond           += timer1.Interval;
            progressBarTime.Value = _sumSecond;

            if (_sumSecond == _settings.TimeAnswer)
            {
                _sumSecond = 0;
                if (_runInfo[_runInfo.Count - 1].RightAnswer == textBoxAnswer.Text.Trim())
                {
                    panelRightAnswerIcon.Visible    = true;
                    panelNotRightAnswerIcon.Visible = false;
                }
                else
                {
                    panelRightAnswerIcon.Visible    = false;
                    panelNotRightAnswerIcon.Visible = true;
                }
                Application.DoEvents();
                Thread.Sleep(500);

                panelRightAnswerIcon.Visible    = false;
                panelNotRightAnswerIcon.Visible = false;

                RunInfo runInfo = _runInfo[_runInfo.Count - 1];
                runInfo.Answer = textBoxAnswer.Text;

                labelAllInfo.Text = (Convert.ToInt32(labelAllInfo.Text) + 1).ToString();
                if (runInfo.Answer == runInfo.RightAnswer)
                {
                    labelRightInfo.Text = (Convert.ToInt32(labelRightInfo.Text) + 1).ToString();
                }
                else
                {
                    labelNotRightInfo.Text = (Convert.ToInt32(labelNotRightInfo.Text) + 1).ToString();
                }

                textBoxAnswer.Text = "";

                progressBarTime.Value = 0;

                _runInfo.RemoveAt(_runInfo.Count - 1);
                _runInfo.Add(runInfo);

                if (runInfo.Number >= _settings.CountExercise)
                {
                    MessageBox.Show("Выполнение задания завершено", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    buttonStartStop_Click(null, null);
                    return;
                }
                GenerateNewExercise();
            }
            timer1.Enabled = true;
        }
Beispiel #2
0
        /// <summary>
        /// Генерация нового задания
        /// </summary>
        private void GenerateNewExercise()
        {
            string rightAnswer = "";

            do
            {
                labelCalculateFirst.Text  = _random.Next(_settings.MinDigit, _settings.MaxDigit + 1).ToString();
                labelCalculateSecond.Text = _random.Next(_settings.MinDigit, _settings.MaxDigit + 1).ToString();


                switch (_settings.TypeExercise)
                {
                case TypeExercises.Adding:
                    labelCalculateSign.Text = "+";
                    rightAnswer             = (Convert.ToInt32(labelCalculateFirst.Text) +
                                               Convert.ToInt32(labelCalculateSecond.Text)).ToString();
                    break;

                case TypeExercises.Subtraction:
                    labelCalculateSign.Text = "-";
                    rightAnswer             = (Convert.ToInt32(labelCalculateFirst.Text) -
                                               Convert.ToInt32(labelCalculateSecond.Text)).ToString();
                    break;

                case TypeExercises.Multiplication:
                    labelCalculateSign.Text = "*";
                    rightAnswer             = (Convert.ToInt32(labelCalculateFirst.Text) *
                                               Convert.ToInt32(labelCalculateSecond.Text)).ToString();
                    break;

                case TypeExercises.Division:
                    labelCalculateSign.Text = "/";
                    if (labelCalculateSecond.Text != "0")
                    {
                        if (Convert.ToInt32(labelCalculateFirst.Text) % Convert.ToInt32(labelCalculateSecond.Text) == 0)
                        {
                            rightAnswer = (Convert.ToInt32(labelCalculateFirst.Text) /
                                           Convert.ToInt32(labelCalculateSecond.Text)).ToString();
                        }
                        else
                        {
                            rightAnswer = "-1";
                        }
                    }
                    break;
                }
            }while (_settings.IsPositiveValueExpected && rightAnswer != "" &&
                    Convert.ToInt32(rightAnswer) < 0);

            var runInfo = new RunInfo
            {
                Exercise = labelCalculateFirst.Text + " " +
                           labelCalculateSign.Text + " " + labelCalculateSecond.Text,
                RightAnswer = rightAnswer
            };

            if (_runInfo.Count == 0)
            {
                runInfo.Number = 1;
            }
            else
            {
                runInfo.Number = _runInfo.Count + 1;
            }

            labelNumberInfo.Text = runInfo.Number + " из " + _settings.CountExercise;
            _runInfo.Add(runInfo);
        }