private static bool NormalQuiz(Quiz q, out WordElement[] waitList) { int r = lastRand, max = 2 * Math.Max(DictService.WordsCount, DictService.MeansCount); float ratio = DictService.WordsCount * 1.0f / DictService.MeansCount; while (r == lastRand) r = rand.Next(max); lastRand = r; bool isWord = (r % 2 == 1); r /= 2; //get basic data if (isWord) { var word = DictService.WordAt(ratio < 1.0f ? (int)(r * ratio) : r); q.quest = word.Letters; waitList = DictService.GetMeansByWId(word.Id); } else { var mean = DictService.MeanAt(ratio > 1.0f ? (int)(r / ratio) : r); q.quest = mean.Meaning; waitList = DictService.GetWordsByMId(mean.Id); } return isWord; }
public static Quiz GetQuiz() { Quiz q = new Quiz(); WordElement[] waitList; bool isWord = isAdapt ? AdaptQuiz(q, out waitList) : NormalQuiz(q, out waitList); //insert answers var anss = new List<Tuple<string, bool>>(); int r = rand.Next(waitList.Length); anss.Add(new Tuple<string, bool>(waitList[r].GetStr(), true)); for (int a = 1; a < 5; a++) { WordElement ele; do { r = rand.Next((int)((isWord ? DictService.MeansCount : DictService.WordsCount) * 1.4)); ele = (isWord ? DictService.MeanAt(r) as WordElement : DictService.WordAt(r) as WordElement); ele = ele ?? waitList.ElementAt(r % waitList.Count()); } while (anss.Exists(x => ele.GetStr() == x.Item1)); bool isRight = waitList.Any(x => x.GetId() == ele.GetId()); anss.Add(new Tuple<string, bool>(ele.GetStr(), isRight)); } q.choices = anss.Shuffle(rand).ToArray(); return q; }
private static bool AdaptQuiz(Quiz q, out WordElement[] waitList) { int r = lastRand; while (r == lastRand) r = rand.Next(DictService.WrongCount); var stat = DictService.EleAt(lastRand = r); q.quest = stat.str; bool isWord = true; waitList = DictService.GetMeansByWord(stat); if (waitList == null) { isWord = false; waitList = DictService.GetWordsByMean(stat); } return isWord; }
private void RefreshQuiz() { try { curQuiz = QuizService.GetQuiz(); curQuiz?.init(); } catch (Exception e) { e.CopeWith("get quiz"); return; } quest.OutlineColor = Color.Silver; quest.BackgroundColor = Color.White; (quest.Content as Label).Text = curQuiz.quest; int a = 0; foreach (var f in choices) { f.OutlineColor = Color.Silver; f.BackgroundColor = Color.White; (f.Content as Label).Text = curQuiz.choices[a++].Item1; } foreach (var l in chdess) l.Text = " "; }