Esempio n. 1
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);
        }
Esempio n. 2
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);
        }