private bool CheckSelection(SelectableQuestion q, ref int lifeCount) { Console.WriteLine(); Console.Write("A. "); var input = -1; int.TryParse(Console.ReadLine(), out input); if (!q.Check(input - 1)) { if (--lifeCount == 0) { return(false); } else { Console.WriteLine(); Console.WriteLine($"오답입니다! (남은 목숨 : {lifeCount}개)"); return(CheckSelection(q, ref lifeCount)); } } else { return(true); } }
public MCQuestionUserControl(SelectableQuestion selectableQuestion, SelectableQuestionResponse response, int index) { this.selectableQuestion = selectableQuestion; this.index = index; this.response = response; InitializeComponent(); this.toggleButtonCheckedHandler = (s, e) => { this.radioBtn_Checked(s, e); }; this.toggleButtonUnCheckedHandler = (s, e) => { this.radioBtn_UnChecked(s, e); }; }
private static void CreateMCQuestion(SelectableQuestion question, int index, FlowDocument flowDocument, bool showAnswer, bool showResponse, SelectableQuestionResponse response) { System.Windows.Documents.Section questionSection = new System.Windows.Documents.Section(); flowDocument.Blocks.Add(questionSection); // Shuffle options List <int> optionIndexList = new List <int>(); if (question.RandomOption) { Random rand = new Random((int)DateTime.Now.Ticks); while (true) { int i = rand.Next(question.QuestionOptionCollection.Count * 10) % question.QuestionOptionCollection.Count; bool found = false; foreach (int temp in optionIndexList) { if (temp == i) { found = true; break; } } if (!found) { optionIndexList.Add(i); } if (optionIndexList.Count == question.QuestionOptionCollection.Count) { break; } Thread.Sleep(10); } } else { for (int i = 0; i < question.QuestionOptionCollection.Count; i++) { optionIndexList.Add(i); } } System.Windows.Documents.Section questionContentBlock = CreateContentControl(question.Content, (index + 1).ToString() + ". ", null, response); Paragraph lastParagraph = null; if (questionContentBlock.Blocks.LastBlock is Paragraph) { lastParagraph = questionContentBlock.Blocks.LastBlock as Paragraph; } if (lastParagraph == null) { lastParagraph = new Paragraph(); questionContentBlock.Blocks.Add(lastParagraph); } if (showResponse) { if (Enumerable.Count <string>(response.OptionIdList) > 0) { for (int i = 0; i < question.QuestionOptionCollection.Count; i++) { QuestionOption option = question.QuestionOptionCollection[optionIndexList[i]]; if (option.Id == response.OptionIdList[0]) { lastParagraph.Inlines.Add(CreateText(" ( " + (char)('A' + i) + " )")); break; } } } else { lastParagraph.Inlines.Add(CreateText("( )")); } } else { lastParagraph.Inlines.Add(CreateText("( )")); } if (showAnswer) { for (int i = 0; i < question.QuestionOptionCollection.Count; i++) { QuestionOption option = question.QuestionOptionCollection[optionIndexList[i]]; if (option.IsCorrect) { lastParagraph.Inlines.Add(CreateText(" 正确答案:" + (char)('A' + i))); break; } } } questionSection.Blocks.Add(questionContentBlock); for (int i = 0; i < question.QuestionOptionCollection.Count; i++) { QuestionOption option = question.QuestionOptionCollection[optionIndexList[i]]; System.Windows.Documents.Section optionSec = CreateContentControl(option.OptionContent, string.Format("\t{0}. ", (char)('A' + i)), null, response); List <Block> tempList = new List <Block>(); tempList.AddRange(optionSec.Blocks); optionSec.Blocks.Clear(); questionSection.Blocks.AddRange(tempList); } }
private IEnumerable <string> GetQuestionImageFiles(Question question) { foreach (string src in GetImageFiles(question.Content.Content)) { yield return(src); } foreach (string src in GetImageFiles(question.Solution.Content)) { yield return(src); } if (question is SelectableQuestion) { SelectableQuestion selectableQuestion = question as SelectableQuestion; foreach (QuestionOption option in selectableQuestion.QuestionOptionCollection) { foreach (string optionImageSrc in GetImageFiles(option.OptionContent.Content)) { yield return(optionImageSrc); } } } else if (question is FIBQuestion) { FIBQuestion fibQuestion = question as FIBQuestion; foreach (QuestionBlank blank in fibQuestion.QuestionBlankCollection) { foreach (QuestionContent refAnswer in blank.ReferenceAnswerList) { foreach (string blankImageSrc in GetImageFiles(refAnswer.Content)) { yield return(blankImageSrc); } } } } else if (question is MAQuestion) { MAQuestion maQuestion = question as MAQuestion; foreach (MAQuestionOption option in maQuestion.OptionList) { foreach (var optionImageSrc in GetImageFiles(option.LeftContent.Content)) { yield return(optionImageSrc); } foreach (var optionImageSrc in GetImageFiles(option.RightContent.Content)) { yield return(optionImageSrc); } } } else if (question is ESQuestion) { ESQuestion esQuestion = question as ESQuestion; foreach (var refAnswerImageSrc in GetImageFiles(esQuestion.ReferenceAnswer.Content)) { yield return(refAnswerImageSrc); } } else if (question is CPQuestion) { CPQuestion cpQuestion = question as CPQuestion; foreach (var subQuestion in cpQuestion.SubQuestions) { foreach (var subQuestionImageSrc in GetQuestionImageFiles(subQuestion as Question)) { yield return(subQuestionImageSrc); } } } }