コード例 #1
0
    void Start()
    {
        this.client = GameObject.Find("Network").GetComponent <Client>();
        this.Score  = GameObject.Find("Game").GetComponent <Score>();


        if (this.name == "Answer")
        {
            Enigma.answerObject = this.GetComponent <Text>();
        }
        if (this.name == "Result")
        {
            Enigma.resultObject = this.GetComponent <Text>();
        }
        if (this.name == "Question")
        {
            Enigma.nbAnswers      = 0;
            Enigma.questionObject = this.GetComponent <Text>();
            //CSV part
            //row[0] : question ; row[1] : answer ; row[2] : explainations

            //ENCODAGE : UTF8-16-LE
            csv = Resources.Load <TextAsset>("Enigmes/Enigma");

            string[] row = CSV_reader.GetRandomLine(csv.text);

            Enigma.question      = row[0];
            Enigma.answer        = row[1];
            Enigma.explainations = row[2];
            addLineBreaks();    //for question + explainations

            this.GetComponent <Text>().text = Enigma.question;
        }
    }
コード例 #2
0
    public void init()
    {
        ChallengeVerticalClick.typeChallenge = (TypeChallenge)Enum.Parse(typeof(TypeChallenge), this.transform.parent.name.Split('_')[1]);
        System.Random ran = new System.Random();
        int           aleat;

        ChallengeVerticalClick.quantityToWin = ran.Next(20, 100);
        //random type of Building
        TypeBuilding tb;

        aleat = ran.Next(0, Enum.GetNames(typeof(TypeBuilding)).Length);
        tb    = (TypeBuilding)Enum.Parse(typeof(TypeBuilding), Enum.GetNames(typeof(TypeBuilding))[aleat], true);
        //here we only use building with material resources
        while (Enum.IsDefined(typeof(TypeBuildingStat), tb.ToString()))
        {
            aleat = ran.Next(0, Enum.GetNames(typeof(TypeBuilding)).Length);
            tb    = (TypeBuilding)Enum.Parse(typeof(TypeBuilding), Enum.GetNames(typeof(TypeBuilding))[aleat], true);
        }

        ChallengeVerticalClick.resourceToWin = main.getNameResourceOrStatProduced(tb.ToString());


        //CSV part
        //row[0] : question ; row[1] : answer ; row[2] : explainations ; after : propositions
        //VraiFaux : answer = Proposition0 ou answer = Proposition1
        //QCM : answer = Proposition0 ou answer = Proposition1 ou answer = Proposition2

        //ENCODAGE : UTF8-16-LE
        //last line of file usually blank --> to be removed!
        //csv = Resources.Load<TextAsset>("Challenges/ChallengesFiles/" + ChallengeVerticalClick.typeChallenge.ToString() + "/" + ChallengeVerticalClick.typeChallenge.ToString() + "_" + tb.ToString());

        if (main.level == 0) //collège
        {
            csv = Resources.Load <TextAsset>("Challenges/ChallengesFiles/College/" + ChallengeVerticalClick.typeChallenge.ToString() + "/" + ChallengeVerticalClick.typeChallenge.ToString() + "_" + tb.ToString());
            Debug.Log("college");
        }
        else
        {
            csv = Resources.Load <TextAsset>("Challenges/ChallengesFiles/Lycee/" + ChallengeVerticalClick.typeChallenge.ToString() + "/" + ChallengeVerticalClick.typeChallenge.ToString() + "_" + tb.ToString());
            Debug.Log("lycee");
        }
        Debug.Log("File : " + typeChallenge.ToString() + "_" + tb.ToString());
        row = CSV_reader.GetRandomLine(csv.text);


        if (ChallengeVerticalClick.typeChallenge == TypeChallenge.QCM)
        {
            ChallengeVerticalClick.nbPropositions = 3;
        }
        else
        {
            ChallengeVerticalClick.nbPropositions = 2;
        }


        ChallengeVerticalClick.question = row[0];
        addLineBreaks();
        ChallengeVerticalClick.answer          = row[1];
        ChallengeVerticalClick.explainations   = row[2];
        ChallengeVerticalClick.propositions    = new string[nbPropositions];
        ChallengeVerticalClick.propositions[0] = row[3];
        ChallengeVerticalClick.propositions[1] = row[4];
        if (ChallengeVerticalClick.nbPropositions == 3)
        {
            ChallengeVerticalClick.propositions[2] = row[5];
        }



        canvasChallenge = this.transform.parent.GetComponent <Canvas>();

        foreach (Text text in canvasChallenge.GetComponentsInChildren <Text>())
        {
            switch (text.name)
            {
            case "Question":
                text.text = ChallengeVerticalClick.question;
                break;

            case "Result":
                resultText = text;
                break;

            case "Proposition0":
                if (typeChallenge == TypeChallenge.QCM)
                {
                    text.text = ChallengeVerticalClick.propositions[0];
                }
                break;

            case "Proposition1":
                if (typeChallenge == TypeChallenge.QCM)
                {
                    text.text = ChallengeVerticalClick.propositions[1];
                }
                break;

            case "Proposition2":
                if (typeChallenge == TypeChallenge.QCM)
                {
                    text.text = ChallengeVerticalClick.propositions[2];
                }
                break;
            }
        }

        foreach (SpriteRenderer sp in canvasChallenge.GetComponentsInChildren <SpriteRenderer>())
        {
            if (sp.name == "background")
            {
                ChallengeVerticalClick.background = sp;
            }
        }
    }
コード例 #3
0
    public void init(TypeChallenge tc, MinorIsland island, Building myBuilding)
    {
        this.Client = GameObject.Find("Network").GetComponent <Client>();

        canvasChallenge = this.transform.parent.GetComponent <Canvas>();

        this.building    = myBuilding;
        this.minorIsland = island;

        this.typeChallenge = tc;
        if (typeChallenge == TypeChallenge.QCM)
        {
            this.nbPropositions = 3;
        }
        else
        {
            this.nbPropositions = 2;
        }


        //CSV part
        //row[0] : question ; row[1] : answer ; row[2] : explainations ; after : propositions
        //VraiFaux : answer = Proposition0 ou answer = Proposition1
        //QCM : answer = Proposition0 ou answer = Proposition1 ou answer = Proposition2

        //ENCODAGE : UTF8-16-LE
        //last line of file usually blank --> to be removed!
        //csv = Resources.Load<TextAsset>("Challenges/ChallengesFiles/" + typeChallenge.ToString() + "/" + typeChallenge.ToString() + "_" + myBuilding.TypeBuilding.ToString());
        if (RegisterScene.level == 0)   //collège
        {
            csv = Resources.Load <TextAsset>("Challenges/ChallengesFiles/College/" + typeChallenge.ToString() + "/" + typeChallenge.ToString() + "_" + myBuilding.TypeBuilding.ToString());
        }
        else
        {
            csv = Resources.Load <TextAsset>("Challenges/ChallengesFiles/Lycee/" + typeChallenge.ToString() + "/" + typeChallenge.ToString() + "_" + myBuilding.TypeBuilding.ToString());
        }

        Debug.Log("File : " + typeChallenge.ToString() + "_" + myBuilding.TypeBuilding.ToString());


        string[] row = CSV_reader.GetRandomLine(csv.text);

        try
        {
            this.question = row[0];
        }
        catch
        {
            error = true;
        }
        finally
        {
            if (!error)
            {
                addLineBreaks();
                this.answer          = row[1];
                this.explainations   = row[2];
                this.propositions    = new string[nbPropositions];
                this.propositions[0] = row[3];
                this.propositions[1] = row[4];
                if (this.nbPropositions == 3)
                {
                    this.propositions[2] = row[5];
                }


                foreach (Text text in canvasChallenge.GetComponentsInChildren <Text>())
                {
                    switch (text.name)
                    {
                    case "Question":
                        text.text = this.question;
                        break;

                    case "Result":
                        resultText = text;
                        break;

                    case "Proposition0":
                        if (typeChallenge == TypeChallenge.QCM)
                        {
                            text.text = this.propositions[0];
                        }
                        break;

                    case "Proposition1":
                        if (typeChallenge == TypeChallenge.QCM)
                        {
                            text.text = this.propositions[1];
                        }
                        break;

                    case "Proposition2":
                        if (typeChallenge == TypeChallenge.QCM)
                        {
                            text.text = this.propositions[2];
                        }
                        break;
                    }
                }

                foreach (SpriteRenderer sp in canvasChallenge.GetComponentsInChildren <SpriteRenderer>())
                {
                    if (sp.name == "background")
                    {
                        this.background = sp;
                    }
                }
            }
            else
            {
                minorIsland.displayPopup("Oups ! Une erreur s'eest produite, veuillez ré-essayer ...", 3);
                Destroy(GameObject.Find("Challenge_" + typeChallenge + "_" + minorIsland.nameMinorIsland));
            }
        }
    }