Beispiel #1
0
    protected void PrepareQuestion(QuestionData.question q)
    {
        HideAllChoices();

        activeQuestion = q;

        question.text       = q.content;
        additionalInfo.text = "";

        //foreach (QuestionData.answer answer in q.answers)
        for (int i = 0; i < q.answers.Count; i++)
        {
            QuestionData.answer answer = q.answers[i];
            if (i < choices.Length)
            {
                UIButton choice = choices[i];
                ChangeButtonColor(choice, Color.white);

                UILabel label = choice.transform.FindChild("Label").GetComponent <UILabel>();

                if (label != null)
                {
                    label.text = answer.text;
                }
                choice.gameObject.SetActive(true);
            }
        }

        _enableTimer = true;
    }
Beispiel #2
0
    protected void OnCategoryContinue()
    {
        var btn = UIHelper.GetSelectedButton(chooseCategoryButtons);

        var pillarType = GetPillarTypeFromColorString(btn.tagText.ToLower());

        QuestionData.question q = qaController.GetNextQuestion(null, pillarType, true);

        ShowQuestionsPanel(q);
    }
Beispiel #3
0
    public void ShowQuestionsPanel(QuestionData.question q)
    {
        SetButtonEnabled(true);

        MainGameController.ShowHud(false);
        UINavigationController.PushBackground("/MainBackground");
        UINavigationController.PushController(questionDialog);

        PrepareQuestion(q);
    }
Beispiel #4
0
    void Convert(TextAsset csv, string targetFile, string section)
    {
        QuestionData qData = new QuestionData();

        if (System.IO.File.Exists(XmlManager.XmlPath + targetFile))
        {
            qData = QuestionData.LoadAsInstance(XmlManager.XmlPath + targetFile);
            if (qData == null)
            {
                Debug.Log(string.Format("Target File {0} is exist, but it's content is null", targetFile));
                qData = new QuestionData();
            }
        }

        StringReader reader = new StringReader(csv.text);

        using (CsvReader csvReader = new CsvReader(reader, false))
        {
            int fieldCount = csvReader.FieldCount;
            Debug.Log(fieldCount);
            while (csvReader.ReadNextRecord())
            {
                string colorCode = csvReader[0];

                // Color Code pass check
                if ((colorCode != "B" && colorCode != "G" && colorCode != "R" &&
                     colorCode != "Y" && colorCode != "P" && colorCode != "O") ||
                    string.IsNullOrEmpty(colorCode))
                {
                    continue;
                }

                // Get the question content
                var qcontent = csvReader[2];

                QuestionData.question question = new QuestionData.question();
                question.content = qcontent.Trim();
                question.section = section;
                question.type    = GetColorNameFromCode(colorCode);


                qData.questions.Add(question);
            }
        }

        QuestionData.Save(targetFile, qData);

        //Debug.Log("Converted " + count);
    }
    void Convert(TextAsset csv, string targetFile, string section)
    {
        QuestionData qData = new QuestionData();
        if (System.IO.File.Exists(XmlManager.XmlPath + targetFile))
        {
            qData = QuestionData.LoadAsInstance(XmlManager.XmlPath + targetFile);
            if (qData == null)
            {
                Debug.Log(string.Format("Target File {0} is exist, but it's content is null", targetFile));
                qData = new QuestionData();
            }
        }

        StringReader reader = new StringReader(csv.text);

        using (CsvReader csvReader = new CsvReader(reader, false))
        {
            int fieldCount = csvReader.FieldCount;
            Debug.Log(fieldCount);
            while (csvReader.ReadNextRecord())
            {
                string colorCode = csvReader[0];

                // Color Code pass check
                if ((colorCode != "B" && colorCode != "G" && colorCode != "R" &&
                    colorCode != "Y" && colorCode != "P" && colorCode != "O") ||
                    string.IsNullOrEmpty(colorCode))
                {
                    continue;
                }

                // Get the question content
                var qcontent = csvReader[2];

                QuestionData.question question = new QuestionData.question();
                question.content = qcontent.Trim();
                question.section = section;
                question.type = GetColorNameFromCode(colorCode);

                qData.questions.Add(question);
            }
        }

        QuestionData.Save(targetFile, qData);

        //Debug.Log("Converted " + count);
    }
Beispiel #6
0
    private void StartElement(ref QuestionData qData, XmlReader xml)
    {
        switch (xml.Name)
        {
        case "question":
            q = new QuestionData.question();
            break;

        case "answers":
            break;

        case "answer":
            answer        = new QuestionData.answer();
            answer.option = xml.GetAttribute(0);
            break;
        }
    }
Beispiel #7
0
    private void FixTypeBasedOnSection(ref QuestionData.question q)
    {
        /*
         * blue= quran
         *  green= hadith
         *  yellow=islamic history
         *  orange=islamic science
         *  pink= general knowledge
         *  purble=prophets*/

        if (q.section.ToLower() == "quran")
        {
            q.type = "blue";
        }

        if (q.section.ToLower() == "hadith")
        {
            q.type = "green";
        }

        if (q.section.ToLower() == "islamic science")
        {
            q.type = "orange";
        }

        if (q.section.ToLower() == "islamic history")
        {
            q.type = "yellow";
        }

        if (q.section.ToLower() == "general knowledge")
        {
            q.type = "red";
        }

        if (q.section.ToLower().Contains("prophets"))
        {
            q.type = "purple";
        }
    }
    private void StartElement(ref QuestionData qData, XmlReader xml)
    {
        switch (xml.Name)
        {
            case "question":
                q = new QuestionData.question();
                break;

            case "answers":
                break;

            case "answer":
                answer = new QuestionData.answer();
                answer.option = xml.GetAttribute(0);
                break;
        }
    }
Beispiel #9
0
    public void ShowQuestion(Node node)
    {
        QuestionData.question q = GetNextQuestion(node);

        ShowQuestionsPanel(q);
    }
Beispiel #10
0
    protected IEnumerator ValidateChoice(int choice)
    {
        _enableTimer = false;
        _counterTime = 0;
        bool isCorrect = false;

        SetButtonEnabled(false);

        List <int> corrects = new List <int>();

        for (int index = 0; index < activeQuestion.answers.Count; index++)
        {
            QuestionData.answer answer = activeQuestion.answers[index];
            if (answer.correct)
            {
                corrects.Add(index);
            }

            if (index == choice && answer.correct && !isCorrect)
            {
                isCorrect = true;
            }
        }

        if (choice < 0)
        {
            isCorrect = false;
        }

        if (isCorrect == false && choice >= 0)
        {
            UIButton button = choices[choice];
            ChangeButtonColor(button, Color.red);
        }

        for (int cIndex = 0; cIndex < corrects.Count; cIndex++)
        {
            int correctIndex = corrects[cIndex];
            ChangeButtonColor(choices[correctIndex], Color.green);
        }

        float waitTime = 3;

        if (activeQuestion != null)
        {
            additionalInfo.text = activeQuestion.info;
            if (activeQuestion.info.Trim() != "")
            {
                waitTime = 6;
            }
        }

        yield return(new WaitForSeconds(waitTime));

        activeQuestion = null;

        UINavigationController.DismissAllControllers();
        UINavigationController.DismissBackground("/MainBackground");
        if (OnChoiceSelected != null)
        {
            OnChoiceSelected(isCorrect);
        }
        //GameBoard.EndTurn(isCorrect);
    }
Beispiel #11
0
    private QuestionData.question GetNextQuestion(Node node, GameData.PillarType defaultPillar, bool useDefaultPillar)
    {
        QuestionData.question result = null;

        // First get the pillar color code from the node that being selected by the player
        GameData.PillarType qtype;
        if (node != null)
        {
            qtype = GameData.GetColorTypeFromNodeType(node.nodeType);
        }
        else
        {
            qtype = defaultPillar;
        }

        if (useDefaultPillar)
        {
            qtype = defaultPillar;
        }

        // Create temp question list to fetch on
        List <QuestionData.question> questions = new List <QuestionData.question>();

        // Find on which colors are we about to take the question list from
        if (questionsMap.ContainsKey(qtype))
        {
            questions = questionsMap[qtype];
        }
        else // We are having QuestionType == Random here
        {
            // If we don't have the pillar color mapped on the questionsMap, just random the section

            int index = Random.Range(0, questionsMap.Keys.Count - 1);

            // Search our random key to get the list of the questions
            int i = 0;
            foreach (var qsValues in questionsMap.Keys)
            {
                if (index == i)
                {
                    questions = questionsMap[qsValues];
                    break;
                }
                i++;
            }
        }

        bool found = false;

        // We loop until we found the question that not being used yet, it's very dangerous, might end up infinite loop
        // TODO: DON'T USE LOOP
        while (!found)
        {
            int qRandomNo = Random.Range(0, questions.Count - 1);
            var que       = questions[qRandomNo];
            if (usedQuestions.Contains(que) == false)
            {
                result = que;
                usedQuestions.Add(que);

                found = true;
            }
        }

        if (result == null)
        {
            usedQuestions.Clear();
            result = QuestionData.current.questions[0];
        }

        return(result);
    }