Esempio n. 1
0
    public override void Begin()
    {
        base.Begin();

        // Pick number of pieces of code
        progress    = 0;
        MaxProgress = numCodeToReview;

        // Generate all the code we will show
        codeToReview = new List <int[]>();
        codeValid    = new List <bool[]>();
        codeApproved = new bool[MaxProgress];
        currentCode  = 0;

        for (int i = 0; i < MaxProgress; i++)
        {
            // Choose whether this should be correct
            bool correct = Random.Range(0, 10) > 5;

            // Pick code length
            int codeLength = Random.Range(minCodeLength, maxCodeLength);

            // Generate the code
            int[] code = correct ? ProgrammingTask.GetSnippetOrder(codeLength, codeSnippets.Length) : ProgrammingTask.GetRandomSnippets(codeLength, codeSnippets.Length);
            codeToReview.Add(code);

            // Decide which pieces of code are correct
            bool[] codeCorrect = new bool[codeLength];
            for (int j = 0; j < code.Length; j++)
            {
                // If it is supposed to be correct, just set it to true
                if (correct)
                {
                    codeCorrect[j] = true;
                }
                else
                {
                    // For first 2 and last, they should be a fixed thing
                    if (j == 0 && code[j] != 0)
                    {
                        codeCorrect[j] = false;
                    }
                    else if ((j == 1 || j == code.Length - 1) && code[j] != 1)
                    {
                        codeCorrect[j] = false;
                    }
                    else
                    {
                        codeCorrect[j] = Random.Range(0, 10) > 5;
                    }
                }
            }

            codeValid.Add(codeCorrect);
            codeApproved[i] = false;
        }

        // Place the first piece of code
        PlaceCode(codeToReview[0], codeValid[0]);
    }