コード例 #1
0
ファイル: Block.cs プロジェクト: lukezya/BBRV-SourceCode
    // Use this for initialization
    void Start()
    {
        GameObject         stack              = GameObject.Find("Stack");
        StackCreator       stackCreator       = stack.GetComponent <StackCreator>();
        BinaryStackCreator binaryStackCreator = stack.GetComponent <BinaryStackCreator>();
        PowerStackCreator  powerStackCreator  = stack.GetComponent <PowerStackCreator>();
        SquareStackCreator squareStackCreator = stack.GetComponent <SquareStackCreator>();

        placeArrow = false;
        if (stackCreator)
        {
            num      = stackCreator.currNum;
            txt.text = "factorial (" + num + ")";

            stackCreator.blockVal.Add("factorial (" + num + ")");
        }
        if (binaryStackCreator)
        {
            binaryNum = binaryStackCreator.currInt;
            txt.text  = "postOrder (" + binaryNum + ")";
        }
        if (powerStackCreator)
        {
            int x = powerStackCreator.currx;
            int y = powerStackCreator.curry;
            txt.text = "power (" + x + ", " + y + ")";
            powerStackCreator.blockVal.Add("power (" + x + ", " + y + ")");
        }
        if (squareStackCreator)
        {
            n        = squareStackCreator.n;
            txt.text = "square (" + n + ")";
            squareStackCreator.blockVal.Add("square (" + n + ")");
        }
    }
コード例 #2
0
    // Use this for initialization
    void Start()
    {
        GameObject stack = GameObject.Find("Stack");

        if (stack.GetComponent <StackCreator>() != null)
        {
            stackCreator = stack.GetComponent <StackCreator>();

            operatorVal = stackCreator.operateVal;

            num = stackCreator.currNum;
            if (num <= 0)
            {
                baseCase = true;
                txt.text = "1";
                stackCreator.instVal.Add(txt.text);
            }
            else
            {
                txt.text = num + " x factorial (" + (num - operatorVal) + ")";
                //Debug.Log(txt.text);
                stackCreator.instVal.Add(txt.text);
            }
        }
        if (stack.GetComponent <BinaryStackCreator>() != null)
        {
            binaryStackCreator = stack.GetComponent <BinaryStackCreator>();

            if (binaryStackCreator.direction != "")
            {
                txt.text = binaryStackCreator.direction;
            }
        }

        if (stack.GetComponent <PowerStackCreator>() != null)
        {
            powerStackCreator = stack.GetComponent <PowerStackCreator>();
            //Set text
            if (powerStackCreator.curry == 0)
            {
                baseCase = true;
                txt.text = powerStackCreator.returnVal + "";//"1";
                powerStackCreator.instVal.Add(txt.text);
            }
            else
            {
                //string line = powerStackCreator.returnVal2;
                //line = line.Replace("n", powerStackCreator.)
                txt.text = powerStackCreator.currx + " x  power (" + powerStackCreator.currx + ", " + powerStackCreator.curry + " - 1)";
                powerStackCreator.instVal.Add(txt.text);
            }
        }

        if (stack.GetComponent <SquareStackCreator>() != null)
        {
            squareStackCreator = stack.GetComponent <SquareStackCreator>();
            if (squareStackCreator.n == 1)
            {
                baseCase = true;
                txt.text = squareStackCreator.returnVal + "";
                squareStackCreator.instVal.Add(txt.text);
            }
            else
            {
                string line = squareStackCreator.returnVal2;
                line = line.Replace("n", squareStackCreator.n + "");
                //int start = line.IndexOf("(");
                //int end = line.IndexOf(")");
                //string result = line.Substring(start + 1, end - start - 1);
                //line = line.Replace(result, n + " -1");
                txt.text = line;//squareStackCreator.returnVal2;//"square (" + squareStackCreator.n + " - 1)";// also needs to change
                squareStackCreator.instVal.Add(txt.text);
            }
        }
    }