Пример #1
0
    private void RandomGenerate()
    {
        System.Random random = new System.Random();


        for (int i = 0; i < MAX_COUNT; i++)
        {
            if (i != 1) //+-*/ 부호를 표시하는 부분을 제외하고
            {
                quizCubes[i].textMeshProArray[0].SetText(random.Next(0, 16).ToString());
                quizCubes[i].textMeshProArray[1].SetText(random.Next(0, 16).ToString());
                quizCubes[i].textMeshProArray[2].SetText(random.Next(0, 16).ToString());
                quizCubes[i].textMeshProArray[3].SetText(random.Next(0, 16).ToString());
            }
        }

        quizCubes[1].textMeshProArray[0].SetText("+");
        quizCubes[1].textMeshProArray[1].SetText("-");
        quizCubes[1].textMeshProArray[2].SetText("X");
        quizCubes[1].textMeshProArray[3].SetText("+");


        switch (random.Next(0, MAX_IMAGE_COUNT))
        {
        case 0:
            currentBonus = CALC_BONUS_STATE.ADDBOOK;
            bonusCubeImage.GetComponent <SpriteData>().SetImage(0);    //보너스 문제
            break;

        case 1:
            currentBonus = CALC_BONUS_STATE.SUBTRACT_BOOK;
            bonusCubeImage.GetComponent <SpriteData>().SetImage(1);    //보너스 문제
            break;

        case 2:
            currentBonus = CALC_BONUS_STATE.ADDTREE;
            bonusCubeImage.GetComponent <SpriteData>().SetImage(2);    //보너스 문제
            break;

        case 3:
            currentBonus = CALC_BONUS_STATE.SUBTRACT_TREE;
            bonusCubeImage.GetComponent <SpriteData>().SetImage(3);    //보너스 문제
            break;
        }


        int j = random.Next(0, 4);
        int randomInt1;

        int.TryParse(quizCubes[0].textMeshProArray[j].text, out randomInt1);
        int randomInt3;

        int.TryParse(quizCubes[2].textMeshProArray[j].text, out randomInt3);
        string randomMark;

        randomMark = quizCubes[1].textMeshProArray[j].text;

        switch (randomMark)
        {
        case "+":
            finalAnswer = randomInt1 + randomInt3;
            break;

        case "-":
            finalAnswer = randomInt1 - randomInt3;
            break;

        case "X":
            finalAnswer = randomInt1 * randomInt3;
            break;
        }

        finalAnswer += bonusCount;
    }