Exemplo n.º 1
0
    public virtual Question GetQuestion(int alternatives)
    {
        int level = testMode ? testLevel : CurrentLevel();
        //Debug.Log("I Courses GetQuestions level: " + level);

        List <string> qs = null;

        /*List<int> keys = new List<int>(questions.Keys);
         * foreach (int key in keys) Debug.Log(" Finns i questions: " + key);
         * Debug.Log("Finns questions[" +level + "] i GetQuestion?  ... "+ questions.ContainsKey(level));*/// + questions[level]);
        if (questions[level] != null)
        {
            qs = questions[level];
        }


        string q = null;

        if (questions[level] != null)
        {
            q = qs[rnd.Next(qs.Count)];
        }
        //Debug.Log("I GetQuestions q: " + q);

        string a = null;

        if (q != null)
        {
            a = answers[q];
        }
        //Debug.Log("I GetQuestions a: " + a);

        var added = new List <string>();
        //Debug.Log("I GetQuestions added: " + added);


        var res = new Question(this, level, questionIDs[q], q, a);
        //Debug.Log("I GetQuestions res: " + res);


        List <string> ans = Enumerable.ToList(answers.Values);

        //Debug.Log("I GetQuestions ans: " + ans);
        //while (true /*alternatives > 0*/)
        for (int i = alternatives; i > 0; i--)
        {
            string cand = ans[rnd.Next(ans.Count)];
            //Debug.Log("I GetQuestions cand: " + cand);
            if (a != cand && added.IndexOf(cand) == -1)
            {
                added.Add(cand);
                res.AddAlternative(cand);
                alternatives--;
            }
        }
        return(res);
    }