//button enabled only during quiz skips actual qestion private void nextBTN_Click(object sender, EventArgs e) { //if user click next to skip question if (answersTXT.All(d => d.Cursor == Cursors.Hand)) { Scores["not answered"]++; //confirm answer to get next QuizMannager.ConfirmAnswer(null); WriteQuestion(); } //if user click next after clicking check button else { WriteQuestion(); } }
//ask a question public void WriteQuestion() { checkBTN.Enabled = false; nextBTN.Enabled = true; ClearAnswersLabels(); //get question (it'll be randomized) var question = QuizMannager.GetQuestion(); //assign question text to label questionTXT.Text = question.Text; //assign answers to labels for (int i = 0; i < answersTXT.Length; i++) { answersTXT[i].Text = question.Answers[i]; answersTXT[i].Cursor = Cursors.Hand; } }
//enabled only if any label is checked process answer private void checkBTN_Click(object sender, EventArgs e) { //converiting labels selections into bool list representation var userAnswers = new List <bool>(); foreach (var label in answersTXT) { userAnswers.Add(label.ForeColor == CheckedColor); } //get correct answers by colors and set them to answer labels and reset cursor var answer = QuizMannager.ConfirmAnswer(userAnswers); for (int i = 0; i < answer.Length; i++) { answersTXT[i].ForeColor = answer[i]; answersTXT[i].Cursor = Cursors.Arrow; } //if there is no error if (answer.All(a => a == Color.Green || a == Color.White)) { Scores["correct"]++; } else { Scores["wrong"]++; } //if check btn is disabled that means user clicked skip and next button click is unnesesary if (!checkBTN.Enabled) { WriteQuestion(); } //except that w8 for user click next else { checkBTN.Enabled = false; } }