コード例 #1
0
ファイル: FightSim.cs プロジェクト: Paulobergine/D-BASTON
    //Couroutine qui après 5 secondes, lance les dés adverses
    IEnumerator jet2(bool startDroite)
    {
        yield return(new WaitForSeconds(5.0f));

        //Instancie le nombre de dés adverses en fonction de la valeur du slider et récupère son résultat
        //Si le dé part de droite
        dice4.SetActive(true);
        if (startDroite == true)
        {
            r4 = value24.value();
        }
        else
        {
            r4 = value14.value();
        }
        resultatAttacked.Add((int)r4 + 1);

        //Si deux dés
        if (nbAt == 2)
        {
            dice5.SetActive(true);
            if (startDroite == true)
            {
                r5 = value25.value();
            }
            else
            {
                r5 = value15.value();
            }
            resultatAttacked.Add((int)r5 + 1);
        }

        //Si trois dés
        else if (nbAt == 3)
        {
            dice5.SetActive(true);
            dice6.SetActive(true);
            if (startDroite == true)
            {
                r5 = value25.value();
            }
            else
            {
                r5 = value15.value();
            }
            if (startDroite == true)
            {
                r6 = value26.value();
            }
            else
            {
                r6 = value16.value();
            }
            resultatAttacked.Add((int)r5 + 1);
            resultatAttacked.Add((int)r6 + 1);
        }
        //Trie du tableau contenant les résultats des dés adverses
        resultatAttacked.Sort();
    }
コード例 #2
0
ファイル: FightSim.cs プロジェクト: Paulobergine/D-BASTON
    //Méthode qui gère les dés et le résultat
    void Update()
    {
        //Si tous les territoires sont désactivés (pour les collisions)
        if (active)
        {
            //Désactivation des "boutons" passer et menu (pour les collisions)
            passer.SetActive(false);
            menu.SetActive(false);

            //Variables pour savoir qui attaque et qui se fait attaquer
            int tourJoueur  = CountryManager.instance.TourJoueur;
            int nbJoueurAtt = Country.theTribes.IndexOf(CountryManager.instance.countrySelectedAttacked.country.tribe);

            //Variable pour savoir si le dé part de la gauche ou la droite
            bool startDroite = false;

            //Case of pour savoir quels dés instancier en fonction de qui attaque et de qui se fait attaquer
            switch (tourJoueur)
            {
            //Le joueur rouge attaque...
            case 0:
                //Instantiation des dés sur le modèle du dé "R"ouge à "D"roite
                dice1   = Instantiate <GameObject>(diceRD);
                dice2   = Instantiate <GameObject>(diceRD);
                dice3   = Instantiate <GameObject>(diceRD);
                value11 = dice1.GetComponent <Dice>();
                value12 = dice2.GetComponent <Dice>();
                value13 = dice3.GetComponent <Dice>();
                switch (nbJoueurAtt)
                {
                //...le joueur bleu
                case 1:
                    dice4   = Instantiate <GameObject>(diceBG);
                    dice5   = Instantiate <GameObject>(diceBG);
                    dice6   = Instantiate <GameObject>(diceBG);
                    value24 = dice4.GetComponent <Dice2>();
                    value25 = dice5.GetComponent <Dice2>();
                    value26 = dice6.GetComponent <Dice2>();
                    jetDes.SetActive(true);
                    break;

                //...le joueur vert
                case 2:
                    dice4   = Instantiate <GameObject>(diceVG);
                    dice5   = Instantiate <GameObject>(diceVG);
                    dice6   = Instantiate <GameObject>(diceVG);
                    value24 = dice4.GetComponent <Dice2>();
                    value25 = dice5.GetComponent <Dice2>();
                    value26 = dice6.GetComponent <Dice2>();
                    jetVVR.SetActive(true);
                    break;

                //...le joueur jaune
                case 3:
                    dice4   = Instantiate <GameObject>(diceJG);
                    dice5   = Instantiate <GameObject>(diceJG);
                    dice6   = Instantiate <GameObject>(diceJG);
                    value24 = dice4.GetComponent <Dice2>();
                    value25 = dice5.GetComponent <Dice2>();
                    value26 = dice6.GetComponent <Dice2>();
                    jetJVR.SetActive(true);
                    break;
                }
                startDroite = true;
                break;

            //Le joueur bleu attaque...
            case 1:
                dice1   = Instantiate <GameObject>(diceBG);
                dice2   = Instantiate <GameObject>(diceBG);
                dice3   = Instantiate <GameObject>(diceBG);
                value21 = dice1.GetComponent <Dice2>();
                value22 = dice2.GetComponent <Dice2>();
                value23 = dice3.GetComponent <Dice2>();
                switch (nbJoueurAtt)
                {
                //...le joueur rouge
                case 0:
                    dice4   = Instantiate <GameObject>(diceRD);
                    dice5   = Instantiate <GameObject>(diceRD);
                    dice6   = Instantiate <GameObject>(diceRD);
                    value14 = dice4.GetComponent <Dice>();
                    value15 = dice5.GetComponent <Dice>();
                    value16 = dice6.GetComponent <Dice>();
                    jetDes.SetActive(true);
                    break;

                //...le joueur vert
                case 2:
                    dice4   = Instantiate <GameObject>(diceVD);
                    dice5   = Instantiate <GameObject>(diceVD);
                    dice6   = Instantiate <GameObject>(diceVD);
                    value14 = dice4.GetComponent <Dice>();
                    value15 = dice5.GetComponent <Dice>();
                    value16 = dice6.GetComponent <Dice>();
                    jetBVV.SetActive(true);
                    break;

                //...le joueur jaune
                case 3:
                    dice4   = Instantiate <GameObject>(diceJD);
                    dice5   = Instantiate <GameObject>(diceJD);
                    dice6   = Instantiate <GameObject>(diceJD);
                    value14 = dice4.GetComponent <Dice>();
                    value15 = dice5.GetComponent <Dice>();
                    value16 = dice6.GetComponent <Dice>();
                    jetBVJ.SetActive(true);
                    break;
                }
                break;

            //Le joueur vert attaque...
            case 2:
                switch (nbJoueurAtt)
                {
                //...le joueur rouge
                case 0:
                    dice1   = Instantiate <GameObject>(diceVG);
                    dice2   = Instantiate <GameObject>(diceVG);
                    dice3   = Instantiate <GameObject>(diceVG);
                    value21 = dice1.GetComponent <Dice2>();
                    value22 = dice2.GetComponent <Dice2>();
                    value23 = dice3.GetComponent <Dice2>();
                    dice4   = Instantiate <GameObject>(diceRD);
                    dice5   = Instantiate <GameObject>(diceRD);
                    dice6   = Instantiate <GameObject>(diceRD);
                    value14 = dice4.GetComponent <Dice>();
                    value15 = dice5.GetComponent <Dice>();
                    value16 = dice6.GetComponent <Dice>();
                    jetVVR.SetActive(true);
                    break;

                //...le joueur bleu
                case 1:
                    dice1   = Instantiate <GameObject>(diceVD);
                    dice2   = Instantiate <GameObject>(diceVD);
                    dice3   = Instantiate <GameObject>(diceVD);
                    value11 = dice1.GetComponent <Dice>();
                    value12 = dice2.GetComponent <Dice>();
                    value13 = dice3.GetComponent <Dice>();
                    dice4   = Instantiate <GameObject>(diceBG);
                    dice5   = Instantiate <GameObject>(diceBG);
                    dice6   = Instantiate <GameObject>(diceBG);
                    value24 = dice4.GetComponent <Dice2>();
                    value25 = dice5.GetComponent <Dice2>();
                    value26 = dice6.GetComponent <Dice2>();
                    jetBVV.SetActive(true);
                    startDroite = true;
                    break;

                //...le joueur jaune
                case 3:
                    dice1   = Instantiate <GameObject>(diceVG);
                    dice2   = Instantiate <GameObject>(diceVG);
                    dice3   = Instantiate <GameObject>(diceVG);
                    value21 = dice1.GetComponent <Dice2>();
                    value22 = dice2.GetComponent <Dice2>();
                    value23 = dice3.GetComponent <Dice2>();
                    dice4   = Instantiate <GameObject>(diceJD);
                    dice5   = Instantiate <GameObject>(diceJD);
                    dice6   = Instantiate <GameObject>(diceJD);
                    value14 = dice4.GetComponent <Dice>();
                    value15 = dice5.GetComponent <Dice>();
                    value16 = dice6.GetComponent <Dice>();
                    jetVVJ.SetActive(true);
                    break;
                }
                break;

            //Le joueur jaune attaque...
            case 3:
                switch (nbJoueurAtt)
                {
                //...le joueur rouge
                case 0:
                    dice1   = Instantiate <GameObject>(diceJG);
                    dice2   = Instantiate <GameObject>(diceJG);
                    dice3   = Instantiate <GameObject>(diceJG);
                    value21 = dice1.GetComponent <Dice2>();
                    value22 = dice2.GetComponent <Dice2>();
                    value23 = dice3.GetComponent <Dice2>();
                    dice4   = Instantiate <GameObject>(diceRD);
                    dice5   = Instantiate <GameObject>(diceRD);
                    dice6   = Instantiate <GameObject>(diceRD);
                    value14 = dice4.GetComponent <Dice>();
                    value15 = dice5.GetComponent <Dice>();
                    value16 = dice6.GetComponent <Dice>();
                    jetJVR.SetActive(true);
                    break;

                //...le joueur bleu
                case 1:
                    dice1   = Instantiate <GameObject>(diceJD);
                    dice2   = Instantiate <GameObject>(diceJD);
                    dice3   = Instantiate <GameObject>(diceJD);
                    value11 = dice1.GetComponent <Dice>();
                    value12 = dice2.GetComponent <Dice>();
                    value13 = dice3.GetComponent <Dice>();
                    dice4   = Instantiate <GameObject>(diceBG);
                    dice5   = Instantiate <GameObject>(diceBG);
                    dice6   = Instantiate <GameObject>(diceBG);
                    value24 = dice4.GetComponent <Dice2>();
                    value25 = dice5.GetComponent <Dice2>();
                    value26 = dice6.GetComponent <Dice2>();
                    jetBVJ.SetActive(true);
                    startDroite = true;
                    break;

                //...le joueur vert
                case 2:
                    dice1   = Instantiate <GameObject>(diceJD);
                    dice2   = Instantiate <GameObject>(diceJD);
                    dice3   = Instantiate <GameObject>(diceJD);
                    value11 = dice1.GetComponent <Dice>();
                    value12 = dice2.GetComponent <Dice>();
                    value13 = dice3.GetComponent <Dice>();
                    dice4   = Instantiate <GameObject>(diceVG);
                    dice5   = Instantiate <GameObject>(diceVG);
                    dice6   = Instantiate <GameObject>(diceVG);
                    value24 = dice4.GetComponent <Dice2>();
                    value25 = dice5.GetComponent <Dice2>();
                    value26 = dice6.GetComponent <Dice2>();
                    jetVVJ.SetActive(true);
                    startDroite = true;
                    break;
                }
                break;
            }

            //Instancie le nombre de dés en fonction de la valeur du slider et récupère son résultat
            dice1.SetActive(true);

            //Si le dé part de droite...
            if (startDroite == true)
            {
                r = value11.value();
            }
            else
            {
                r = value21.value();
            }
            resultat.Add((int)r + 1);

            //Si deux dés
            if (nbDe == 2)
            {
                dice2.SetActive(true);
                if (startDroite == true)
                {
                    r2 = value12.value();
                }
                else
                {
                    r2 = value22.value();
                }
                resultat.Add((int)r2 + 1);
            }

            //Si trois dés
            else if (nbDe == 3)
            {
                dice2.SetActive(true);
                if (startDroite == true)
                {
                    r2 = value12.value();
                }
                else
                {
                    r2 = value22.value();
                }
                dice3.SetActive(true);
                if (startDroite == true)
                {
                    r3 = value13.value();
                }
                else
                {
                    r3 = value23.value();
                }
                resultat.Add((int)r2 + 1);
                resultat.Add((int)r3 + 1);
            }

            //Trie du tableau contenant les résultats des dés
            resultat.Sort();

            //Début de la couroutine pour les autres dés
            coroutine4 = jet2(startDroite);
            StartCoroutine(coroutine4);

            //Démarre les 2 couroutines
            coroutine = wait();
            StartCoroutine(coroutine);
            coroutine2 = wait2(resultat, resultatAttacked);
            StartCoroutine(coroutine2);
            coroutine5 = resBattle(resultat, resultatAttacked);
            StartCoroutine(coroutine5);

            //Les territoires redevienent actifs
            active = false;
        }
    }