public ResultsForm(Question[][] mainAnswers)
 {
     _resultsJaggedArray = (Question[][])mainAnswers.Clone();
     InitializeComponent();
     for (int outer = 0; outer < _resultsJaggedArray.Length; outer++)
     {
         if (_resultsJaggedArray[outer] != null)
         {
             for (int inner = 0; inner < _resultsJaggedArray[outer].Length; inner++)
             {
                 Console.WriteLine(_resultsJaggedArray[outer] + " | " + _resultsJaggedArray[outer][inner]);
             }
         }
     }
 }
Exemple #2
0
        private void buttonDragDropHandler(object sender, DragEventArgs e)
        {
            // only process drag operation if correct data type
            if (e.Data.GetDataPresent(typeof(Question)))
            {
                // Extract Q from drag data, make sure Q is not null
                Question question = (Question)e.Data.GetData(typeof(Question));
                if (question != null)
                {
                    Button button = sender as Button;

                    // Store all answers in the _answers jag arr
                    int answer = 0;

                    if (!int.TryParse(button.Text, out answer)) { answer = 0; }
                    if (_answers[answer] == null)
                    {
                        //jag arr hasn't been created so create first entry
                        _answers[answer] = new Question[1];
                    }
                    else
                    {
                        // Already have entries in Jag arr, resize to len + 1
                        Array.Resize(ref _answers[answer], _answers[answer].Length + 1);
                    }

                    // Add Q to jag arr

                    _answers[answer][_answers[answer].Length - 1] = new Question(question.TheQuestion.ToString(), question.TheAnswer, Convert.ToInt32(button.Text));

                    // Test if correct ans, display dialog, remove from listbox
                    if (button.Text == question.TheAnswer.ToString())
                    {
                        // remove Q from listbox
                        questionsListBox.Items.RemoveAt(questionsListBox.SelectedIndex);
                        MessageBox.Show(button.Text + " is Correct!");
                    }
                    else
                    {
                        MessageBox.Show("Wrong answer, try again.");
                    }
                }
            }
        }
Exemple #3
0
        private void resetProgram()
        {
            Array.Clear(_questions, 0, _questions.Length);

            // Clear all ans from jagged Arr and set arr index to NULL
            for (int i = 0; i < _answers.Length; i++)
            {
                if (_answers[i] != null)
                {
                    Array.Clear(_answers[i], 0, _answers[i].Length);
                    _answers[i] = null;
                }
            }

            int maxAnswer = _squaresCount * _squaresCount - 1;

            Random random = new Random();
            for (int i = 0; i < _numberOfQuestions; i++)
            {
                int randomLeft = random.Next(0, maxAnswer + 1);
                int randomRight = random.Next(0, maxAnswer - randomLeft + 1);
                int answer = randomLeft + randomRight;
                string question = randomLeft.ToString() + " + " + randomRight.ToString();
                _questions[i] = new Question()
                {
                    TheQuestion = question,
                    TheAnswer = answer
                };
            }

            // reset the Qs in ListBox
            questionsListBox.Items.Clear();
            for (int i = 0; i < _questions.Length; i++) { questionsListBox.Items.Add(_questions[i]); }
        }