コード例 #1
0
        public int LoadQuestion(LoadQuestionVM loadQuestionVM)
        {
            Random rnd            = new Random();
            var    questionToDo   = Questions.Where(x => x.IsDeleted == false && x.IsCorrectAnswer != true).ToList();
            var    id             = rnd.Next(questionToDo.Count);
            var    randomQuestion = questionToDo[id];

            loadQuestionVM.Question.Text = "\"" + randomQuestion.Content + "\"";

            for (int i = 0; i < loadQuestionVM.Answers.Count(); i++)
            {
                loadQuestionVM.Answers[i].Text = "";
            }


            var idButton = rnd.Next(loadQuestionVM.Answers.Count);

            loadQuestionVM.Answers[idButton].Text = randomQuestion.Answer;


            var randomAnswers = Questions.Where(x => x.IsDeleted == false && x.Id != randomQuestion.Id).Select(x => x.Answer).ToList();

            var    idRandomAnswers1 = rnd.Next(randomAnswers.Count);
            string badAnswer1       = randomAnswers[idRandomAnswers1];

            randomAnswers.RemoveAt(idRandomAnswers1);

            var    idRandomAnswers2 = rnd.Next(randomAnswers.Count);
            string badAnswer2       = randomAnswers[idRandomAnswers2];

            randomAnswers.RemoveAt(idRandomAnswers2);

            var    idRandomAnswers3 = rnd.Next(randomAnswers.Count);
            string badAnswer3       = randomAnswers[idRandomAnswers3];

            randomAnswers.RemoveAt(idRandomAnswers3);

            string[] badAnswers  = { badAnswer1, badAnswer2, badAnswer3 };
            int      idBadAnswer = 0;

            for (int i = 0; i < loadQuestionVM.Answers.Count(); i++)
            {
                if (loadQuestionVM.Answers[i].Text == "")
                {
                    loadQuestionVM.Answers[i].Text = badAnswers[idBadAnswer];
                    idBadAnswer++;
                }
            }

            return(randomQuestion.Id);
        }
コード例 #2
0
        public QuizForm(QuestionService questionService, UserPanelForm userPanelForm)
        {
            InitializeComponent();
            this.questionService = questionService;
            this.userPanelForm   = userPanelForm;

            answerButtons = new List <Button>();
            answerButtons.Add(answerButton1);
            answerButtons.Add(answerButton2);
            answerButtons.Add(answerButton3);
            answerButtons.Add(answerButton4);

            loadQuestionView = new LoadQuestionVM(questionLabel, answerButtons);
            actualIdQuestion = questionService.LoadQuestion(loadQuestionView);
            answerTimer.Start();
            completedTasksProgressBar.Value = questionService.UpdateProgress();
            progressPercentLabel.Text       = completedTasksProgressBar.Value + " %";
        }