/// <summary> /// 获得下一个单选 /// </summary> /// <param name="multipleChoices"></param> /// <returns></returns> public MultipleChoice GetNextMultipleChoice(CaseAnalysis resultCase) { CaseAnalysis ca = db.CaseAnalysiss.Find(resultCase.Id); db.Entry(ca).Collection(x => x.Topics).Load();//手动读取List CaseAnalysis andlysis1 = db.CaseAnalysiss.Find(1); db.Entry(andlysis1).Collection(x => x.Topics).Load();//手动读取List if (resultCase.Topics.Count == ca.Topics.Count) { //判断是否答完 List <CaseAnalysis> andlysis = db.CaseAnalysiss.OrderBy(e => e.Id).ToList(); List <int> CaseIds = (List <int>)Session["CaseAnalysises"]; if (CaseIds.Count >= andlysis.Count) { MultipleChoice end = new MultipleChoice(); ViewBag.end = 1; return(end); } return(null); } return(ca.Topics[resultCase.Topics.Count]); //Random rm = new Random(); //MultipleChoice mc = ca.Topics[rm.Next(ca.Topics.Count)];//随机数最大值不能超过list的总数 //if (resultCase.Topics.Contains(mc)) //{ // return GetNextMultipleChoice(resultCase); //} //return mc; }
private void ShowProblemData() { long typeId = -1; if (selectType != null) { typeId = selectType.id; } problemList.Clear(); switch (problemKind) { case QuestionHistory.TYPE_CHOICE: problemList.AddRange(Choice.LoadAllChoice(typeId)); break; case QuestionHistory.TYPE_MULTIPLECHOICE: problemList.AddRange(MultipleChoice.LoadAllMultipleChoice(typeId)); break; case QuestionHistory.TYPE_JUDGE: problemList.AddRange(Judge.LoadAllMultipleChoice(typeId)); break; } UpdateUI(); }
public ActionResult Submit(MultipleChoice multipleChoice) { List <MultipleChoice> result = (List <MultipleChoice>)Session["Result"]; CaseAnalysis resultCase = (CaseAnalysis)Session["ResultCase"]; if (result == null) { result = new List <MultipleChoice>(); result.Add(multipleChoice); Session["Result"] = result; } else { result.Add(multipleChoice); } if (resultCase == null) { resultCase = new CaseAnalysis(); resultCase.Topics = new List <MultipleChoice>(); resultCase.Topics.Add(multipleChoice); Session["ResultCase"] = resultCase; } if (multipleChoice.CaseId != 0) { return(ListAnalysis()); } return(List()); }
protected override QuestionInputModel ConvertToDerived2( Yw_SubjectContent content) { var inputModel = new MultipleChoice(); if (content != null) { var c = content as Yw_SubjectSelectContent; inputModel.StemType = (UeditorType)c.Ysc_Content_Obj.StemType; inputModel.ContentType = (UeditorType)c.Ysc_Content_Obj.ContentType; inputModel.Display = c.Ysc_Content_Obj.Display; UeditorType contentType = (UeditorType)c.Ysc_Content_Obj.ContentType; inputModel.Options = c.Ysc_Content_Obj.Options .Select(o => UeditorContentFactory.RestoreContent(o.Text, contentType)).ToList(); inputModel.Random = c.Ysc_Content_Obj.Random; UeditorType t = (UeditorType)c.Ysc_Content_Obj.StemType; string name = UeditorContentFactory.RestoreContent(c.Ysc_Content_Obj.Stem, t); inputModel.Name = name; inputModel.Answers = c.Ysc_Answer_Obj.Answers; } else { inputModel.StemType = UeditorType.Text; inputModel.ContentType = UeditorType.Text; inputModel.Display = 1; inputModel.Options = new List <string>(); inputModel.Random = 1; inputModel.Name = string.Empty; inputModel.Answers = new List <int>(); } return(inputModel); }
private void Save() { string file = LineEditor.RequestPath(TYPE, _saveLocation); if (file != null) { try { if (File.Exists(file)) { int selected = MultipleChoice.Show("File already exists. Overwrite?", "No", "", "Yes"); if (selected == 2) { SaveGame(file); } } else { SaveGame(file); } } catch (IOException) { Console.WriteLine("An error occured while saving."); } } }
private void ShowMultipleChoice() { this.problemListView.BeginUpdate(); InitProblemListViewColumns(multipleChoiceColumns, multipleChoiceColumnsWidth, multipleChoiceColumnsTextAligns); problemListView.Items.Clear(); for (int i = 0; i < problemList.Count; i++) { ListViewItem item = new ListViewItem(); MultipleChoice choice = (MultipleChoice)problemList[i]; item.Text = choice.id.ToString(); item.SubItems.Add(choice.content); item.SubItems.Add(choice.aska); item.SubItems.Add(choice.askb); item.SubItems.Add(choice.askc); item.SubItems.Add(choice.askd); item.SubItems.Add(choice.ans); item.SubItems.Add(choice.isDone == 0 ? "否" : "是"); item.SubItems.Add(choice.typeName); problemListView.Items.Add(item); } this.problemListView.EndUpdate(); }
public async Task <IActionResult> CreateMultipleChoice(int id, MultipleChoiceViewModel model) { var folderId = Int32.Parse(Request.Form["folder"]); ViewBag.Categories = _categoryRepo.Categories; if (ModelState.IsValid) { //create new multiple choice MultipleChoice newMC = new MultipleChoice(); newMC.Name = model.Name; newMC.Description = model.Description; newMC.A = model.A; newMC.B = model.B; newMC.C = model.C; newMC.D = model.D; newMC.Answer = model.Answer; _context.MultipleChoices.Add(newMC); await _context.SaveChangesAsync(); //save changes ^^ //create new post and pass it newly saved multiple choice's id as foreign key Post newPost = new Post(); newPost.CourseId = _courseId; newPost.PostCategory = 1; newPost.AssignmentId = newMC.MultipleChoiceId; newPost.FolderId = folderId; _context.Posts.Add(newPost); //everytime we add a post to a folder we update the edit time of the edit col in folder var folderToUpdate = _context.Folders.Where(f => f.FolderId == folderId && f.CourseId == id).First(); folderToUpdate.WhenEdited = DateTime.Now; await _context.SaveChangesAsync(); TempData["Success"] = "Assignment Successfully Created!"; //to be used for views to show activity of Curse UpdateCourse(id); return(RedirectToRoute(new { controller = "Course", action = "Show", id = _courseId })); } return(View(model)); }
/// <summary> /// 判断是否有重复的选题 /// </summary> /// <param name="mc"></param> /// <returns></returns> public bool isCunZai(MultipleChoice mc) { List <MultipleChoice> answer = (List <MultipleChoice>)Session["Answer"]; if (answer == null) { answer = new List <MultipleChoice>(); answer.Add(mc); Session["Answer"] = answer; return(false); } else { foreach (MultipleChoice item in answer) { if (item.Id == mc.Id) { return(true); } } //不存在 answer.Add(mc); Session["Answer"] = answer; return(false); } return(false); }
public MultipleChoicePage(MultipleChoice task, List <int> chosenButtonIndexes) : this(task) { foreach (var index in chosenButtonIndexes) { optionButtons[index].Background = new SolidColorBrush(chosenOptionColor); } }
private MultipleChoice ReturnMultipleChoice(DataRow dr) { MultipleChoice m = new MultipleChoice(); SetTitle(m, dr); m.@enum = ReturnEnums(dr["formQuestionId"].ToString().StringToInt()); return(m); }
private void userControlTst_Load(object sender, EventArgs e) { this.CenterToScreen(); MultipleChoice uc = new MultipleChoice(); flowLayoutPanel1.Controls.Add(uc); qNumber++; checkLabel(); }
public async Task <ActionResult> DeleteConfirmed(int id) { MultipleChoice multipleChoice = await db.MultipleChoices.FindAsync(id); db.MultipleChoices.Remove(multipleChoice); await db.SaveChangesAsync(); return(RedirectToAction("EditQuestions", "Examiner")); }
public void MultipleChoiceConstructorTest() { List <string> choices = new List <string> { "Apple", "Banana", "Carrot" }; MultipleChoice multipleChoice = new MultipleChoice(choices, choices[0]); Assert.AreEqual("Apple", multipleChoice.CorrectAnswer); Assert.AreEqual($"0 - Apple{Environment.NewLine}1 - Banana{Environment.NewLine}2 - Carrot{Environment.NewLine}", multipleChoice.ListOptions()); }
public static MultipleChoice getMultipleChoice() //---------------------------------------------------------- //---------------------------------------------------------- { if (instance == null) { instance = new MultipleChoice(); } return(instance); }
public IActionResult SubmitMultipleChoice(int id, int?assignmentId, int?categoryId, MultipleChoice submission) { //get the actual answer of the assignment //since we know this is only for MC, we go directly to the MC table MultipleChoice assignment = _context.MultipleChoices.Where(m => m.MultipleChoiceId == assignmentId).FirstOrDefault(); var assignmentAnswer = assignment.Answer; //we want the user to only make one submission per assignment //so we check if such a submission exist bool subExist = _context.MultipleChoiceSubmissions.Any(m => m.AssignmentId == assignmentId && m.UserEmail == User.Identity.Name); //only create submission if there isnt a submission already existing if (!subExist) { var userSelectedAnswer = Request.Form["radio"]; MultipleChoiceSubmission newSubmission = new MultipleChoiceSubmission { AssignmentId = (int)assignmentId, Answer = userSelectedAnswer, UserEmail = User.Identity.Name, IsCorrect = assignmentAnswer == userSelectedAnswer }; _context.MultipleChoiceSubmissions.Add(newSubmission); _context.SaveChanges(); } //create new submission to be used for report Submission newSub = new Submission { AssignmentId = (int)assignmentId, CategoryId = 1, CourseId = id, UserEmail = User.Identity.Name }; _context.Add(newSub); _context.SaveChanges(); TempData["Success"] = "Assignment Successfully Submitted!"; //for multiple choice we dont need the actual model to be submitted //all we need is the actual radio button selected return(RedirectToRoute(new { controller = "Course", action = "Show", id = id })); }
// Start is called before the first frame update void Start() { mc = MultipleChoice.getMultipleChoice(); question.GetComponent <InputField>().text = ""; correctAnswer.GetComponent <InputField>().text = ""; for (int i = 0; i < wrongAnswers.Length; i++) { wrongAnswers[i].GetComponent <InputField>().text = ""; } }
public bool Delete(int ID) { MultipleChoice mc = this.multipleChoiceRepository.FindBy(x => x.ID == ID).FirstOrDefault(); if (mc != null) { this.multipleChoiceRepository.Delete(mc); this.unitOfWork.Commit(); return(true); } return(false); }
public async Task <ActionResult> Edit([Bind(Include = "MultipleChoiceId,OptionText1,OptionText2,OptionText3,OptionText4,CorrectChoice,QuestionId")] MultipleChoice multipleChoice) { if (ModelState.IsValid) { db.Entry(multipleChoice).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("EditQuestions", "Examiner")); } ViewBag.QuestionId = multipleChoice.QuestionId; return(View(multipleChoice)); }
public void CreateMultipleChoice(int code, [FromBody] MultipleChoice question) { if (DatabaseContext.Active.Sessions.TryGetValue(code, out AdminInstance admin)) { ThreadPool.QueueUserWorkItem(o => admin.AddMultipleChoice(question)); HttpContext.Response.StatusCode = 201; } else { HttpContext.Response.StatusCode = 412; } }
protected override Yw_SubjectContent GetContent( QuestionInputModel sub, SubjectBll bll, int currentUser, Yw_SubjectContent content) { MultipleChoice subject = sub as MultipleChoice; Yw_SubjectSelectContent selectContent = null; if (content == null) { selectContent = new Yw_SubjectSelectContent(); selectContent.Ysc_CreateTime = DateTime.Now; selectContent.Ysc_Creator = currentUser; selectContent.Ysc_SubjectType = subject.SubjectType; } else { selectContent = content as Yw_SubjectSelectContent; } selectContent.Ysc_Editor = currentUser; selectContent.Ysc_Explain = subject.Explain; if (subject.ContentType == UeditorType.Image) { subject.Options = subject.Options.Select(o => UeditorContentFactory.FetchUrl(o, subject.ContentType)).ToList(); } var options = subject.Options .Select((o, i) => new SubjectOption { Text = o, Key = i }) .ToList(); selectContent.Ysc_Answer_Obj = new SubjectSelectAnswerObj { Answers = subject.Answers }; string stem = UeditorContentFactory.FetchUrl(subject.Name, subject.StemType); selectContent.Ysc_Content_Obj = new SubjectSelectContentObj { StemType = (int)subject.StemType, Stem = stem, ContentType = (int)subject.ContentType, Options = options, Display = subject.Display, Random = subject.Random }; selectContent.Ysc_UpdateTime = DateTime.Now; return(selectContent); }
public RedactMultipleChoicePage(ref MultipleChoice task) { InitializeComponent(); this.task = task; MarkTextBox.Text = task.Mark.ToString(CultureInfo.InvariantCulture); QuestionTextBox.Text = task.Question; foreach (var option in task.Options) { OptionsList.Items.Add(new ComboBoxItem() { Content = option }); var rightAnswerCheckBox = new CheckBox() { Content = option }; if (task.RightAnswersIndexes.Contains(task.Options.IndexOf(option))) { rightAnswerCheckBox.IsChecked = true; } rightAnswerCheckBox.Checked += RightAnswerCheckBoxChecked; rightAnswerCheckBox.Unchecked += RightAnswerCheckBoxUnchecked; RightOptionsSelector.Children.Add(rightAnswerCheckBox); } SetAddNewOption(); SetQuestionButton.Click += SetQuestionButtonClick; SetOptionButton.Click += SetOptionButtonClick; DeleteOptionButton.Click += DeleteOptionButtonClick; SetMarkButton.Click += SetMarkButtonClick; OptionTextBox.TextChanged += OptionTextBoxTextChanged; QuestionTextBox.TextChanged += QuestionTextBoxTextChanged; MarkTextBox.TextChanged += MarkTextBoxTextChanged; OptionsList.SelectionChanged += OptionsListSelectionChanged; SetQuestionButton.IsEnabled = false; SetOptionButton.IsEnabled = false; SetMarkButton.IsEnabled = false; OptionsList.SelectedIndex = 0; }
// GET: MultipleChoices/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MultipleChoice multipleChoice = await db.MultipleChoices.FindAsync(id); if (multipleChoice == null) { return(HttpNotFound()); } return(View(multipleChoice)); }
/// <summary> /// 详情 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Details(int id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MultipleChoice choice = db.MultipleChoices.Find(id); if (id == null) { return(HttpNotFound()); } return(View(choice)); }
public MultipleChoicePage(MultipleChoice task, List <int> chosenButtonIndexes, List <int> rightAnswersIndexes) { InitializeComponent(); optionButtons = new List <ToggleButton>(); isResultPage = true; QuestionBlock.Text = task.Question; for (var optionNum = 0; optionNum < task.Options.Count; optionNum++) { AddOption(optionNum, task.Options[optionNum]); } if (rightAnswersIndexes == null) { } else if (chosenButtonIndexes == null) { foreach (var optionButton in optionButtons) { if (rightAnswersIndexes.Contains(optionButtons.IndexOf(optionButton))) { optionButton.Background = new SolidColorBrush(notChosenRightOptionColor); } } } else { for (var index = 0; index < optionButtons.Count; index++) { if (chosenButtonIndexes.Contains(index) && rightAnswersIndexes.Contains(index)) { optionButtons[index].Background = new SolidColorBrush(chosenRightOptionColor); } else if (!chosenButtonIndexes.Contains(index) && rightAnswersIndexes.Contains(index)) { optionButtons[index].Background = new SolidColorBrush(notChosenRightOptionColor); } else if (chosenButtonIndexes.Contains(index) && !rightAnswersIndexes.Contains(index)) { optionButtons[index].Background = new SolidColorBrush(chosenWrongOptionColor); } } } Answer = new List <int>(); }
public void QuesionController_SubmitQuestion_SubmitDirectory() { QuestionController controller = new QuestionController(); var question = new MultipleChoice { Id = 0, //Answer = new List<string> { "a-zhcy", "b-zhcy" }, Explain = "ex-zhcy", Name = "xuanzti-zhcy", }; ViewResult result = null;//controller.SubmitQuestion(question) as ViewResult; Assert.IsNotNull(result); }
// GET: MultipleChoices/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MultipleChoice multipleChoice = await db.MultipleChoices.FindAsync(id); if (multipleChoice == null) { return(HttpNotFound()); } ViewBag.QuestionText = (from q in db.Questions where q.QuestionId == multipleChoice.MultipleChoiceId select q.QuestionText).FirstOrDefault(); ViewBag.QuestionId = (from q in db.Questions where q.QuestionId == multipleChoice.MultipleChoiceId select q.QuestionId).FirstOrDefault(); return(View(multipleChoice)); }
public void QuesionController_SubmitQuestion_SubmitAfterSaved() { QuestionController controller = new QuestionController(); var question = new MultipleChoice { Id = 10000, //Answers = new List<string> { "a-zhcy-u", "b-zhcy-u" }, //Display = 1, Explain = "ex-zhcy-u-u", Name = "xuanzti-zhcy", }; ViewResult result = null;// controller.SubmitQuestion(question) as ViewResult; Assert.IsNotNull(result); }
public MultipleChoicePage(MultipleChoice task) { InitializeComponent(); optionButtons = new List <ToggleButton>(); isResultPage = false; QuestionBlock.Text = task.Question; for (var optionNum = 0; optionNum < task.Options.Count; optionNum++) { AddOption(optionNum, task.Options[optionNum]); } Answer = new List <int>(); }
private void UpdateData() { if (examType == QuestionHistory.EXAM_TYPE_UNDO) { list.AddRange(MultipleChoice.LoadUndoMultipleChoice(100)); list.AddRange(QuestionHistory.LoadMultipleChoice(QuestionHistory.EXAM_TYPE_WRONG, 10)); } else if (examType == QuestionHistory.EXAM_TYPE_WRONG) { list.AddRange(QuestionHistory.LoadMultipleChoice(QuestionHistory.EXAM_TYPE_WRONG, 100)); } else if (examType == QuestionHistory.EXAM_TYPE_REVIEW) { list.AddRange(QuestionHistory.LoadMultipleChoice(QuestionHistory.EXAM_TYPE_REVIEW, 100)); } list = Util.RandomSortList(list); index = 0; }
private void addQuestionButton_Click(object sender, EventArgs e) { MultipleChoice uc = new MultipleChoice(); uc.Tag = qNumber; if (checkMChoice(qNumber - 1) == true) { qNumber++; flowLayoutPanel1.Controls.Add(uc); if (qNumber > 0) { removeLastButton.Enabled = true; } if (qNumber >= maxQs) { CreateQuizButton.Enabled = true; } checkLabel(); } }
// Saves question to test protected void btnSaveQuestion_Click(object sender, EventArgs e) { // Multiple choice question checked and saved if(rblChooseQuestion.SelectedValue == "Multiple Choice") if(txtMCQuestion.Text != String.Empty) if (txtMC1.Text != String.Empty || txtMC2.Text != String.Empty || txtMC3.Text != String.Empty || txtMC4.Text != String.Empty) { Question newQuestion = new Question(questionCounter, Int32.Parse(ddlPointValue.SelectedValue), "Multiple Choice"); if(rdbMC1.Checked == true) { MultipleChoice newMCQuestion = new MultipleChoice(questionCounter, txtMCQuestion.Text, "A"); } else if (rdbMC2.Checked == true) { MultipleChoice newMCQuestion = new MultipleChoice(questionCounter, txtMCQuestion.Text, "B"); } else if (rdbMC3.Checked == true) { MultipleChoice newMCQuestion = new MultipleChoice(questionCounter, txtMCQuestion.Text, "C"); } else { MultipleChoice newMCQuestion = new MultipleChoice(questionCounter, txtMCQuestion.Text, "D"); } MultipleChoiceChoice MCOption1 = new MultipleChoiceChoice(questionCounter, 'A', txtMC1.Text); MultipleChoiceChoice MCOption2 = new MultipleChoiceChoice(questionCounter, 'A', txtMC2.Text); MultipleChoiceChoice MCOption3 = new MultipleChoiceChoice(questionCounter, 'A', txtMC3.Text); MultipleChoiceChoice MCOption4 = new MultipleChoiceChoice(questionCounter, 'A', txtMC4.Text); questionList.Add(newQuestion); } // True False Question checked and saved if(rblChooseQuestion.SelectedValue == "True False") if(txtTFQuestion.Text != String.Empty) { Question newQuestion = new Question(questionCounter,Int32.Parse(ddlPointValue.SelectedValue), "True/False"); TrueFalse newTFQuestion = new TrueFalse(questionCounter, txtTFQuestion.Text, rblTrueFalse.SelectedValue.ToString()); questionList.Add(newQuestion); } // Fill in the Blank question checked and saved if (rblChooseQuestion.SelectedValue == "Short Answer") if (txtFBAnswer.Text != String.Empty) { Question newQuestion = new Question(questionCounter, Int32.Parse(ddlPointValue.SelectedValue), "Short Answer"); if (txtFBStatementBegin.Text != String.Empty && txtFBStatementEnd.Text != String.Empty) { ShortAnswer newSAQuestion = new ShortAnswer(questionCounter, txtFBStatementBegin.Text, txtFBAnswer.Text, txtFBStatementEnd.Text); } else if(txtFBStatementBegin.Text != String.Empty) { ShortAnswer newSAQuestion = new ShortAnswer(questionCounter, String.Empty, txtFBAnswer.Text, txtFBStatementEnd.Text); } else { ShortAnswer newSAQuestion = new ShortAnswer(questionCounter, txtFBStatementBegin.Text, txtFBAnswer.Text, String.Empty); } questionList.Add(newQuestion); } // Matching question checked and saved if(rblChooseQuestion.SelectedValue == "Matching") { if (txtSectionName.Text != String.Empty) { Question newQuestion = new Question(questionCounter, Int32.Parse(ddlPointValue.SelectedValue), "Matching"); Matching newMatching = new Matching(questionCounter, txtSectionName.Text); if (txtMQuestion1.Text != String.Empty && txtMAnswer1.Text != String.Empty) { MatchingQuestions newChoice1 = new MatchingQuestions(4, txtMQuestion1.Text, txtMAnswer1.Text); } if (txtMQuestion2.Text != String.Empty && txtMAnswer2.Text != String.Empty) { MatchingQuestions newChoice2 = new MatchingQuestions(4, txtMQuestion2.Text, txtMAnswer2.Text); } if (txtMQuestion3.Text != String.Empty && txtMAnswer3.Text != String.Empty) { MatchingQuestions newChoice3 = new MatchingQuestions(4, txtMQuestion3.Text, txtMAnswer3.Text); } if (txtMQuestion4.Text != String.Empty && txtMAnswer4.Text != String.Empty) { MatchingQuestions newChoice4 = new MatchingQuestions(4, txtMQuestion4.Text, txtMAnswer4.Text); } questionList.Add(newQuestion); } } // Essay question checked and saved if (rblChooseQuestion.SelectedValue == "Essay") if (txtEQuestion.Text != String.Empty) { Question newQuestion = new Question(questionCounter, Int32.Parse(ddlPointValue.SelectedValue), "Essay"); Essay newEssayQuestion = new Essay(questionCounter, txtEQuestion.Text); questionList.Add(newQuestion); } // tentative way to have unique questionIds questionCounter++; }
/// <summary> /// Gets the choices for the multiple choice mode. /// </summary> /// <param name="cardID">The card ID.</param> /// <returns></returns> /// <remarks>Documented by Dev03, 2008-01-11</remarks> public MultipleChoice GetChoices(ICard mcCard) { MultipleChoice choices = new MultipleChoice(); MultipleChoice distractors = new MultipleChoice(); MultipleChoice emptyChoices = new MultipleChoice(); // load the correct choices and the distractors if (CurrentQueryDirection == EQueryDirection.Question2Answer) { for (int i = 0; i < mcCard.Answer.Words.Count; i++) { if (CurrentMultipleChoiceOptions.MaxNumberOfCorrectAnswers <= i) break; if (mcCard.Answer.Words[i].Word.Length > 0) choices.Add(new Choice(mcCard.Answer.Words[i].Word, true)); if (!CurrentMultipleChoiceOptions.AllowMultipleCorrectAnswers.Value) break; } for (int i = 0; i < mcCard.AnswerDistractors.Words.Count; i++) { if (mcCard.AnswerDistractors.Words[i].Word.Length > 0) distractors.Add(new Choice(mcCard.AnswerDistractors.Words[i].Word, false)); } } else { for (int i = 0; i < mcCard.Question.Words.Count; i++) { if (CurrentMultipleChoiceOptions.MaxNumberOfCorrectAnswers <= i) break; if (mcCard.Question.Words[i].Word.Length > 0) choices.Add(new Choice(mcCard.Question.Words[i].Word, true)); if (!CurrentMultipleChoiceOptions.AllowMultipleCorrectAnswers.Value) break; } for (int i = 0; i < mcCard.QuestionDistractors.Words.Count; i++) { if (mcCard.QuestionDistractors.Words[i].Word.Length > 0) distractors.Add(new Choice(mcCard.QuestionDistractors.Words[i].Word, false)); } } //load random distractors (if allowed) if (CurrentMultipleChoiceOptions.AllowRandomDistractors.Value) { int numberOfRandomDistractors = CurrentMultipleChoiceOptions.NumberOfChoices.GetValueOrDefault() - choices.Count; //enough distractors available... do not need to search for random distractors if (numberOfRandomDistractors <= distractors.Count) { if (distractors.Count > numberOfRandomDistractors) distractors.Randomize(); choices.AddRange(distractors.GetRange(0, numberOfRandomDistractors)); } else //to less distractors available... search for random distractors { List<ICard> cards = dictionary.Cards.GetCards(new QueryStruct[] { new QueryStruct(mcCard.Chapter, -1) }, QueryOrder.Random, QueryOrderDir.Ascending, numberOfRandomDistractors * 5 + choices.Count); for (int i = 0; i < cards.Count; i++) { if (numberOfRandomDistractors <= distractors.Count) break; if (cards[i].Id == mcCard.Id) continue; IList<IWord> words; if (CurrentQueryDirection == EQueryDirection.Question2Answer) { words = cards[i].Answer.Words; } else { words = cards[i].Question.Words; } if ((words.Count > 0) && (words[0].Word.Length > 0) && !choices.Exists(c => c.Word.Equals(words[0].Word)) && !distractors.Exists(d => d.Word.Equals(words[0].Word))) distractors.Add(new Choice(words[0].Word, false)); } choices.AddRange(distractors); } if (choices.Count < CurrentMultipleChoiceOptions.NumberOfChoices) return emptyChoices; } else { if (distractors.Count == 0) return emptyChoices; int numberOfRandomDistractors = CurrentMultipleChoiceOptions.NumberOfChoices.GetValueOrDefault() - choices.Count; //shuffle if (distractors.Count > numberOfRandomDistractors) distractors.Randomize(); if (numberOfRandomDistractors <= distractors.Count) choices.AddRange(distractors.GetRange(0, numberOfRandomDistractors)); else choices.AddRange(distractors); } choices.Randomize(); return choices; }