void ShowAnswer()
 {
     foreach (var input in m_InputFields)
     {
         QuizHelp helper = input.GetComponent <QuizHelp> ();
         if (helper == null)
         {
             continue;
         }
         helper.ShowGoodAnswer();
     }
 }
    // Use this for initialization
    void Start()
    {
        Button reset = GetComponentInChildren <Button> ();

        reset.onClick.AddListener(OnResetClick);

        QuizGroupHelp quizGroup = GetComponentInChildren <QuizGroupHelp> ();

        InputField[]      inputs = GetComponentsInChildren <InputField> ();
        List <InputField> cache  = new List <InputField> ();

        foreach (var i in inputs)
        {
            if (string.CompareOrdinal(i.name, "InputField-V") == 0)                // it needs a special validator.
            {
                QuizHelp help = i.GetComponent <QuizHelp> ();
                if (help != null)
                {
                    help.Validator = NodeSetValidator;
                }
                continue;
            }

            // by matching names, find a pair of graph nodes for one edge.
            if (i.name.StartsWith("InputField-E"))
            {
                int        pos   = "InputField-E".Length;
                char       group = i.name [pos];
                InputField match = cache.Find(input => input.name[pos] == group);
                if (match == null)
                {
                    cache.Add(i);
                }
                else
                {
                    char order1 = i.name [pos + 1];
                    char order2 = match.name [pos + 1];
                    if (order1 < order2)
                    {
                        quizGroup.AddEdgeInput(i, match);
                    }
                    else
                    {
                        quizGroup.AddEdgeInput(match, i);
                    }
                    cache.Remove(match);
                }
                continue;
            }
        }
    }
    bool ValidateAnswer()
    {
        bool errorFound = false;

        foreach (var input in m_InputFields)
        {
            QuizHelp helper = input.GetComponent <QuizHelp> ();
            if (helper == null)
            {
                continue;
            }
            bool ok = helper.Validate();
            if (!errorFound && !ok)
            {
                errorFound = true;
            }
        }
        return(!errorFound);
    }
Exemple #4
0
    private void OnCommitClick()
    {
        bool errorFound = false;

        InputField[] inputs = Parent.GetComponentsInChildren <InputField> ();        // "inputs" are all active InputFields on canvas.
        foreach (var i in inputs)
        {
            QuizHelp help = i.GetComponent <QuizHelp> ();
            if (help == null)
            {
                continue;
            }
            if (!help.Validate())
            {
                errorFound = true;
            }
        }
        if (!m_GroupHelp.Validate())
        {
            errorFound = true;
        }

        MapType current = GetMapType();
        MapType another = (current == MapType.MapBeijing ? MapType.MapChina : MapType.MapBeijing);

        // Test is finished good.
        if (!errorFound)
        {
            TestStats.Instance.SetTestDone(current, true);
            if (TestStats.Instance.IsTestDone(another))                // Both tests are done...
            {
                TestStats.Instance.MessageText = "顶点与边的集合学习完毕,进入下一阶段的学习";
                //TestStats.Instance.ButtonAction = /* jump to next page */
                TestStats.Instance.ShowMessageBox();
            }
            else
            {
                string message1 = "有向图填写完毕,继续学习无向图";
                string message2 = "无向图填写完毕,继续学习有向图";
                TestStats.Instance.MessageText  = (current == MapType.MapChina ? message1 : message2);
                TestStats.Instance.ButtonAction = () => MapTab.Instance.ShowMap(another);
                TestStats.Instance.ShowMessageBox();
            }
            // Test fails.
        }
        else
        {
            TestStats.Instance.IncErrorCount(current);
            if (TestStats.Instance.GetErrorCount(current) > TestStats.ErrorMax)
            {
                TestStats.Instance.MessageText = "超过三次填写错误,已给出正确答案";
                TestStats.Instance.ShowMessageBox();
                //
                foreach (var i in inputs)
                {
                    QuizHelp help = i.GetComponent <QuizHelp> ();
                    if (help == null)
                    {
                        continue;
                    }
                    help.ShowGoodAnswer();
                }
                m_GroupHelp.ShowGoodAnswer();
            }
            else
            {
                TestStats.Instance.MessageText = "填写错误,已标记错误项";
                TestStats.Instance.ShowMessageBox();
            }
        }
    }