Beispiel #1
0
        public void EndTest()
        {
            if (state != QuizState.Finish)
            {
                return;
            }
            bool isChs = chsRex.IsMatch(quest);
            int  a     = 0;

            if (isAllRight)
            {
                DictService.Report(quest, (short)(isChs ? -4 : -5));
                foreach (var it in choices)
                {
                    if (it.Item2 == ans[a++])
                    {
                        DictService.Report(it.Item1, -2);
                    }
                }
            }
            else
            {
                DictService.Report(quest, (short)(isChs ? 5 : 7));
                foreach (var it in choices)
                {
                    if (it.Item2 != ans[a++])
                    {
                        DictService.Report(it.Item1, (short)(isChs ? 4 : 2));
                    }
                }
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        public IEnumerable <string> GetDescription(int idx)
        {
            IEnumerable <WordElement> trans = DictService.GetMeansByWord(choices[idx].Item1);

            if (trans == null)
            {
                trans = DictService.GetWordsByMean(choices[idx].Item1);
            }
            return(trans.Select(x => x.GetStr()));
        }
Beispiel #5
0
        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);
        }