Beispiel #1
0
    public Question(string val1, string op, string val2, string val3, mathOp mo, quesType qt, string q)
    {
        this.val1     = val1;
        this.val2     = val2;
        this.op       = op;
        this.val3     = val3;
        this.mo       = mo;
        this.qt       = qt;
        this.question = q;
        switch (qt)
        {
        case quesType.Basic:
            ans = val3.ToString();
            break;

        case quesType.Algebra:
            ans = val2.ToString();
            break;

        case quesType.Operation:
            ans = op;
            break;

        default:
            ans = "Error";
            Debug.LogErrorFormat("Unhandled question type: {0}", qt);
            break;
        }
    }
Beispiel #2
0
    Question MakeQuestion(List <mathOp> ops, List <quesType> types)
    {
        quesType qt   = types[Random.Range(0, types.Count)];
        mathOp   mo   = ops[Random.Range(0, types.Count)];
        int      val1 = Random.Range(MINNUM, MAXNUM + 1);
        int      val2 = Random.Range(MINNUM, MAXNUM + 1);
        int      val3 = -23;     // Poor choice of error value, but rolling with it. TODO
        string   sol  = "Error"; // Correct solution that a ship will carry

        switch (mo)
        {
        case mathOp.Add:
            val3 = val1 + val2;
            break;

        case mathOp.Subtract:
            val3 = val1 - val2;
            break;

        case mathOp.Multiply:
            val3 = val1 * val2;
            break;

        default:
            Debug.LogErrorFormat("Unhandled math operator: {0}", mo);
            break;
        }
        string quesStr = "Error";

        switch (qt)
        {
        case quesType.Basic:
            quesStr = string.Format("{0}{1}{2}=?", val1, opMap[mo], val2);
            sol     = val3.ToString();
            break;

        case quesType.Algebra:
            quesStr = string.Format("{0}{1}?={2}", val1, opMap[mo], val3);
            sol     = val2.ToString();
            break;

        case quesType.Operation:
            quesStr = string.Format("{0}?{1}={2}", val1, val2, val3);
            sol     = opMap[mo];
            break;

        default:
            Debug.LogErrorFormat("Unhandled ques type: {0}", qt);
            break;
        }
        Question quesOut = new Question(val1.ToString(), opMap[mo], val2.ToString(), val3.ToString(), mo, qt, quesStr);

        return(quesOut);
    }