[DB-AL] Jeux multijoueur simple.

Toutes les questions sur le développement Mobile, y compris la partie script.
Avatar de l’utilisateur
Paullux
Messages : 68
Inscription : 12 Nov 2015 17:11
Contact :

[DB-AL] Jeux multijoueur simple.

Message par Paullux » 13 Avr 2018 22:33

Bonjour,

Je développe un petit jeu d'échecs : https://play.google.com/store/apps/deta ... hessOnline

Mon jeu utilise Vuforia avec un marker pour faire apparaître un échiquier avec des pièces du jeu d'échecs.

J'ai ajouté un principe de tour par tour ou chacun des deux joueurs peut lorsqu'il doit jouer, sélectionner en appuyant sur une de ses pièces et en cliquant sur la case où il veut la mettre. J'ai aussi ajouté un timer par joueur.

Ce que je voudrais ajouter maintenant c'est un mode multijoueur en ligne avec la création d'ID propre à chaque joueur, par exemple un nom choisis plus un numéro aléatoire.
Je veux créer des parties en ligne, si un joueur lance le jeu, il peut choisir dans une liste des joueurs connectés (qui par exemple créé une partie sur leur téléphone en attente à moins qu'ils rejoignent une nouvelle partie) .

Là, la partie se lance et un des joueurs choisit s'il prend les blancs ou les noirs, l'autre accepte ou pas, en cas de refus, il faut retourner sur la sélection des parties actives.

Et là les seules choses qui est échangé c'est à la fin de son tours, le joueur envoi la case de départ et la case d'arrivée qu'il aura choisit.

Dans les tutos que j'ai vu sur YouTube, il créé une instance d'un préfab qui se déplace dans la scène et interagit avec la scène.

J'ai pas besoin d'un préfab, je veux juste un tuto pour créer la partie avec les outils natif d'Unity, et l'échange des positions départ et arrivé et de la fin du tour. J'ai créé une variable currentPlayer qui a 0 est le joueur blanc et qui à 1 est le joueur noir. Le joueur a qui les blancs auront été attribué ne puisse jouer que les pièces blancs à son tour et inversement.

Après faut gérer les déconnexions.

Je veux bien un peu d'aide et des pistes pour aller dans la bonne direction, par exemple si il existe des tutos sur internet.
Merci d'avance.
J'ai créé un ensemble de jeux :

Un HUB : https://bit.ly/2J6EZTO
Un jeu avec contrôle tactile à l'écran : https://bit.ly/2J3IkTw
Un jeu en VR : https://bit.ly/2h5jdzk
Un jeu en AR : https://bit.ly/2LgMvIo

Il s'agit de FPS pour Android.

Avatar de l’utilisateur
Paullux
Messages : 68
Inscription : 12 Nov 2015 17:11
Contact :

Re: [DB-AL] Jeux multijoueur simple.

Message par Paullux » 14 Avr 2018 18:17

J'ai ajouté à mon jeu un network manager et un network hud dans une "première scène" qui si le joueur est connecté ouvre la scène principal. J'arrive à me connecter sur mon réseau local, ou en passant par les serveurs d'Unity.

Après j'ai créé un préfab joueur avec ce script attaché :

Code : Tout sélectionner

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class PlayerController : NetworkBehaviour {
    public int CurrentPlayer;
    public int JoueurAttrib;

    [SyncVar]
    public int firstPosition, secondPosition, finTour;

    void Start ()
    {
        CurrentPlayer = GameObject.Find("/Canvas").GetComponent<JoueurEnCours>().CurrentJoueur;
        JoueurAttrib = GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().JoueurAttrib;
    }
    void Update()
    {
        if (isLocalPlayer && JoueurAttrib == CurrentPlayer)
        {
            firstPosition = GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().FirstCase;
            secondPosition = GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().SecondCase;
            if (GameObject.Find("/Canvas").GetComponent<JoueurEnCours>().FinCoupIci) finTour = 1;
        }
        if (!isLocalPlayer && finTour == 1)
        {
            GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().FirstCaseValid = firstPosition;
            GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().SecondCaseValid = secondPosition;
            GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().ChangePosition = true;
            finTour = 0;
        }
    }
}
Je ne sais pas encore si ça marche, j'ai un problème, je n'arrive pas à attribuer la variable JoueurAttrib à un de mon script "DetectCaseTouch" :

j'ai essayé :

Code : Tout sélectionner

        if (Network.isServer)
        {
            JoueurAttrib = 1;
        }
        else
        if (Network.isClient)
        {
            JoueurAttrib = 0;
        } 
Cela est incorrect, quelque soit le joueur , JoueurAttrib est toujours égal à zéro.

Comment faire pour que le premier joueur est la variable à 0 et le second à 1.
J'ai créé un ensemble de jeux :

Un HUB : https://bit.ly/2J6EZTO
Un jeu avec contrôle tactile à l'écran : https://bit.ly/2J3IkTw
Un jeu en VR : https://bit.ly/2h5jdzk
Un jeu en AR : https://bit.ly/2LgMvIo

Il s'agit de FPS pour Android.

Avatar de l’utilisateur
Paullux
Messages : 68
Inscription : 12 Nov 2015 17:11
Contact :

Re: [DB-AL] Jeux multijoueur simple.

Message par Paullux » 14 Avr 2018 20:41

En cherchant sur internet, j'ai un peu changer le script :

Code : Tout sélectionner

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class PlayerController : NetworkBehaviour {
    public int CurrentPlayer;
    public int JoueurAttrib;

    [SyncVar(hook = "LectureDeplacement")]

    public int firstPosition, secondPosition, finTour;

    void Start ()
    {
        CurrentPlayer = GameObject.Find("/Canvas").GetComponent<JoueurEnCours>().CurrentJoueur;
        JoueurAttrib = GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().JoueurAttrib;
    }
    void Update()
    {
        if (isLocalPlayer && JoueurAttrib == CurrentPlayer)
        {
            firstPosition = GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().FirstCase;
            secondPosition = GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().SecondCase;
            if (GameObject.Find("/Canvas").GetComponent<JoueurEnCours>().FinCoupIci) finTour = 1;
            EnregistrementDeplacement(firstPosition, secondPosition, finTour);

        }
        if (!isLocalPlayer && finTour == 1)
        {
            LectureDeplacement(firstPosition, secondPosition, finTour);
            finTour = 0;
        }
    }
    public void LectureDeplacement(int FIRSTCASE, int SECONDCASE, int FINTOUR)
    {
        FIRSTCASE = firstPosition;
        SECONDCASE = secondPosition;
        FINTOUR = finTour;
    }


    public void EnregistrementDeplacement(int FIRSTCASE, int SECONDCASE, int FINTOUR)
    {
        if (isServer)
        {
            firstPosition = FIRSTCASE;
            secondPosition = SECONDCASE;
            finTour = FINTOUR;
        }
        else
        {
            EnregistreDeplacementGeneral(FIRSTCASE, SECONDCASE, FINTOUR);
        }
    }
    [Command]
    void EnregistreDeplacementGeneral(int FIRSTCASE, int SECONDCASE, int FINTOUR)
    {
        EnregistrementDeplacement(FIRSTCASE, SECONDCASE, FINTOUR);
    }
}
mais là je bloque sur l'attribution d'une couleur (blanc/noir) pour un joueur. Et donc je ne peux pas tester mon script.
J'ai créé un ensemble de jeux :

Un HUB : https://bit.ly/2J6EZTO
Un jeu avec contrôle tactile à l'écran : https://bit.ly/2J3IkTw
Un jeu en VR : https://bit.ly/2h5jdzk
Un jeu en AR : https://bit.ly/2LgMvIo

Il s'agit de FPS pour Android.

Avatar de l’utilisateur
Paullux
Messages : 68
Inscription : 12 Nov 2015 17:11
Contact :

Re: [DB-AL] Jeux multijoueur simple.

Message par Paullux » 15 Avr 2018 18:22

En me connectant sur mon réseau local, et en mettant un des appareils en host, ou sur des rooms sur internet.

J'arrive à déplacer les pièces et à faire varier le joueur pouvant jouer, mais j'ai toujours un bug, les coups ne sont pas toujours respectés. Voici le code aujourd'hui :

Code : Tout sélectionner

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;



public class PlayerController : NetworkBehaviour {

    public int JoueurAttrib; //if player is white or black (0 = white, 1 = black)
    private NetworkInstanceId playerNetID;
    private Transform myTransform;
    public int CurrentPlayer, firstPosition, secondPosition, finTour;

    [SyncVar]
    public string playerUniqueIdentity;
    [SyncVar]
    public int SyncfirstPosition, SyncsecondPosition, SyncfinTour;
     
    public override void OnStartLocalPlayer()
    {
        GetNetIdentity();
        SetIdentity();
    }

    void Awake()
    {
        myTransform = transform;
    }

    void Start ()
    {

        JoueurAttrib = 1;


        GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().JoueurAttrib = JoueurAttrib;
    }
    void Update()
    {
        CurrentPlayer = GameObject.Find("/Canvas").GetComponent<JoueurEnCours>().CurrentJoueur;
        if (myTransform.name == "" || myTransform.name == "Player(Clone)")
        {
            SetIdentity();
        }


        if (isLocalPlayer)
        {
            firstPosition = GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().FirstCase;
            secondPosition = GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().SecondCase;
            if (GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().FinCoup) finTour = 1;
            EnregistrementDeplacement(firstPosition, secondPosition, finTour);
            finTour = 0;
        }
        if (!isLocalPlayer && SyncfinTour == 1)
        {
            GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().FirstCaseValid = SyncfirstPosition;
            GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().SecondCaseValid = SyncsecondPosition;
            GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().ChangePosition = (SyncfinTour == 1);
            SyncfinTour = 0;
        }
    }

    [Client]
    public void EnregistrementDeplacement(int FIRSTCASE, int SECONDCASE, int FINTOUR)
    {
        if (isServer)
        {
            SyncfirstPosition = FIRSTCASE;
            SyncsecondPosition = SECONDCASE;
            SyncfinTour = FINTOUR;
        }
        else
        {
            CmdEnregistreDeplacement(FIRSTCASE, SECONDCASE, FINTOUR);
        }
    }

    [Command]
    void CmdEnregistreDeplacement(int FIRSTCASE, int SECONDCASE, int FINTOUR)
    {
        EnregistrementDeplacement(FIRSTCASE, SECONDCASE, FINTOUR);
    }

    [Client]
    void GetNetIdentity()
    {
        playerNetID = GetComponent<NetworkIdentity>().netId;
        CmdTellServerMyIdentity(MakeUniqueIdentity());
    }

    void SetIdentity()
    {
        if (isLocalPlayer)
        {
            myTransform.name = playerUniqueIdentity;
        }
        else
        {
            myTransform.name = MakeUniqueIdentity();
        }
    }

    string MakeUniqueIdentity()
    {
        string uniqueName = "Player " + playerNetID.ToString();
        return uniqueName;
    }
    [Command]
    void CmdTellServerMyIdentity(string name)
    {
        playerUniqueIdentity = name;
    }

}
J'ai créé un ensemble de jeux :

Un HUB : https://bit.ly/2J6EZTO
Un jeu avec contrôle tactile à l'écran : https://bit.ly/2J3IkTw
Un jeu en VR : https://bit.ly/2h5jdzk
Un jeu en AR : https://bit.ly/2LgMvIo

Il s'agit de FPS pour Android.

Avatar de l’utilisateur
Paullux
Messages : 68
Inscription : 12 Nov 2015 17:11
Contact :

Re: [DB-AL] Jeux multijoueur simple.

Message par Paullux » 16 Avr 2018 07:55

Finalement, face à la difficulté, j'utilise Lobby Network, une interface graphique pour Unet.

Sinon une dernière question, comment faire pour ajouter un menu en jeu pour choisir les blancs ou les noirs, et le premier qui choisit impose à l'autre son choix ?
J'ai créé un ensemble de jeux :

Un HUB : https://bit.ly/2J6EZTO
Un jeu avec contrôle tactile à l'écran : https://bit.ly/2J3IkTw
Un jeu en VR : https://bit.ly/2h5jdzk
Un jeu en AR : https://bit.ly/2LgMvIo

Il s'agit de FPS pour Android.

Avatar de l’utilisateur
Paullux
Messages : 68
Inscription : 12 Nov 2015 17:11
Contact :

Re: [DB-AL] Jeux multijoueur simple.

Message par Paullux » 21 Avr 2018 09:08

aujourd'hui, le script que j'ai attribué au prefab du joueur est :

Code : Tout sélectionner

using Prototype.NetworkLobby;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;



public class PlayerController : NetworkBehaviour {

    public int CurrentPlayer, firstPosition, secondPosition, finTour;
    public bool first = true;
    
    public GameObject WhiteAttrib, BlackAttrib;

    [SyncVar]
    public int JoueurAttrib, SyncfirstPosition, SyncsecondPosition, SyncfinTour;
    [SyncVar]
    public Color PlayerColor = Color.red;

    void Update()
    {
        if (isLocalPlayer)
        {
            Debug.Log("PlayerColor=" + PlayerColor.ToString());
            CurrentPlayer = GameObject.Find("/Canvas").GetComponent<JoueurEnCours>().CurrentJoueur;
            if (PlayerColor == Color.white) JoueurAttrib = 0;
            if (PlayerColor == Color.black) JoueurAttrib = 1;
            GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().JoueurAttrib = JoueurAttrib;
            if (JoueurAttrib == 0)
            {
                WhiteAttrib.SetActive(true);
                BlackAttrib.SetActive(false);
                PlayerColor = Color.white;
                
            }
            if (JoueurAttrib == 1)
            {
                WhiteAttrib.SetActive(false);
                BlackAttrib.SetActive(true);
                PlayerColor = Color.black;
                
            }

            Debug.Log("Player Controller ID=" + transform.GetComponent<NetworkIdentity>().playerControllerId.ToString());
            firstPosition = GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().FirstCase;
            secondPosition = GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().SecondCase;
            if (GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().FinCoup) finTour = 1;
            EnregistrementDeplacement(firstPosition, secondPosition, finTour);
            finTour = 0;
        }
        if (!isLocalPlayer && SyncfinTour == 1)
        {
            GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().FirstCaseValid = SyncfirstPosition;
            GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().SecondCaseValid = SyncsecondPosition;
            GameObject.Find("/ARCamera").GetComponent<DetectCaseTouch>().ChangePosition = (SyncfinTour == 1);
            SyncfinTour = 0;
        }
    }

    [Client]
    public void EnregistrementDeplacement(int FIRSTCASE, int SECONDCASE, int FINTOUR)
    {
        if (isServer)
        {
            SyncfirstPosition = FIRSTCASE;
            SyncsecondPosition = SECONDCASE;
            SyncfinTour = FINTOUR;
        }
        else
        {
            CmdEnregistreDeplacement(FIRSTCASE, SECONDCASE, FINTOUR);
        }
    }

    [Command]
    void CmdEnregistreDeplacement(int FIRSTCASE, int SECONDCASE, int FINTOUR)
    {
        EnregistrementDeplacement(FIRSTCASE, SECONDCASE, FINTOUR);
    }

}

et j'ai changé dans le script Lobbymanager :

Code : Tout sélectionner

        public override bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer)
        {
            //This hook allows you to apply state data from the lobby-player to the game-player
            //just subclass "LobbyHook" and add it to the lobby object.

            if (_lobbyHooks)
                _lobbyHooks.OnLobbyServerSceneLoadedForPlayer(this, lobbyPlayer, gamePlayer);

            return true;
        } 
par

Code : Tout sélectionner

        public override bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer)
        {
            //This hook allows you to apply state data from the lobby-player to the game-player
            //just subclass "LobbyHook" and add it to the lobby object.

            if (_lobbyHooks)
                _lobbyHooks.OnLobbyServerSceneLoadedForPlayer(this, lobbyPlayer, gamePlayer);

            var cc = lobbyPlayer.GetComponent<LobbyPlayer>();
            var player = gamePlayer.GetComponent<PlayerController>();
            gamePlayer.SetActive(true);
            player.PlayerColor = cc.playerColor;
            

            return true;
        }

Là la couleur définit dans le menu Lobby est bien attribué.

Mais il y a un bug génant, j'ai mis dans chaque version du jeu un script qui gère les déplacements.

Je n'essaye d'échanger que la position avant et après la position après coup, et de déterminer après coup sur chacun des téléphones si le tour est finit pour passé au coup suivant.

Le problème est qu'il y a des coups "oubliés" qui bloque le jeu par exemple chacun des joueurs attends que l'autre joue.
Il y a des pièces qui sont récupérés alors qu'elle ne le devrait pas.

Comment faire qu'il n'y qu'un seul script sur le serveur qui gère les coups, qui gère l'autorisation de jouer des joueurs et qui attendent et demande en continue que le joueur qui doit jouer est fait un coup valide pour après pour laisser le joueur suivant jouer ?

Voici le script qui valide les coups :

Code : Tout sélectionner

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class DetectCaseTouch : MonoBehaviour
{
    public int JoueurAttrib;
    public GameObject PieceSurCase;
    private Color CouleurPiece;
    private bool PremiereSelection = true;
    private int PreviousSlot;
    private int[] PiecesPourIci;
    public Ray ray;
    public bool FinCoup = false;
    public int CurrentPlayer;
    public int[] PieceRecupereBlanc, PieceRecupereNoir;
    private GameObject PieceRecupereParBlanc, PieceRecupereParNoir;
    public int FirstCase, SecondCase, FirstCaseValid, SecondCaseValid;
    public bool ChangePosition = false;

    void Start()
    {
        PiecesPourIci = PieceSurCase.GetComponent<Echiquier>().Pieces;
        PieceRecupereBlanc = new int[16];
        PieceRecupereNoir = new int[16];
        PieceRecupereParBlanc = GameObject.Find("PieceRecupereParBlanc");
        PieceRecupereParNoir = GameObject.Find("PieceRecupereParNoir");
    }

    void Update()
    {

        FinCoup = false;
        if (Input.GetMouseButtonDown(0))
        { // if left button pressed...

            ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            //ray = new Ray(Camera.main.transform.position, Input.mousePosition); 
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                for (int i = 0; i <= 63; i++)
                {
                    if (hit.collider.tag == i.ToString())
                    {

                        Debug.Log(hit.collider.tag);
                        if (!PremiereSelection && PreviousSlot == i)
                        {
                            PieceSurCase.transform.GetChild(0).GetChild(PreviousSlot).GetChild(PiecesPourIci[PreviousSlot] - 1).GetComponent<Renderer>().material.color = CouleurPiece;
                            PremiereSelection = true;
                            break;
                        }
                        CurrentPlayer = GameObject.Find("/Canvas").GetComponent<JoueurEnCours>().CurrentJoueur;

                        if (JoueurAttrib == CurrentPlayer && ((PremiereSelection && PiecesPourIci[i] != 0 && CurrentPlayer == 0 && PiecesPourIci[i] <= 6) || (PremiereSelection && PiecesPourIci[i] != 0 && CurrentPlayer == 1 && PiecesPourIci[i] >= 7)))
                        {
                            PremiereSelection = false;
                            CouleurPiece = PieceSurCase.transform.GetChild(0).GetChild(i).GetChild(PiecesPourIci[i] - 1).gameObject.GetComponent<Renderer>().material.color;
                            PieceSurCase.transform.GetChild(0).GetChild(i).GetChild(PiecesPourIci[i] - 1).GetComponent<Renderer>().material.color = Color.green;
                            PreviousSlot = i;
                            Debug.Log("1 Prev=" + PreviousSlot.ToString());
                            FirstCase = i;
                            break;
                        }


                        if (!PremiereSelection && (PiecesPourIci[i] == 0 || (CurrentPlayer == 0 && PiecesPourIci[i] >= 7) || (CurrentPlayer == 1 && PiecesPourIci[i] <= 6)))
                        {
                            if (PiecesPourIci[i] != 0) PieceSurCase.transform.GetChild(0).GetChild(i).GetChild(PiecesPourIci[i] - 1).gameObject.SetActive(false);

                            if (PiecesPourIci[i] != 0)
                            {
                                if (CurrentPlayer == 0)
                                {
                                    for (int nB = 0; nB <= 15; nB++)
                                    {
                                        if (PieceRecupereBlanc[nB] == 0)
                                        {
                                            PieceRecupereBlanc[nB] = PiecesPourIci[i];
                                            PieceRecupereParBlanc.transform.GetChild(0).GetChild(nB).GetChild(PieceRecupereBlanc[nB] - 1).gameObject.SetActive(true);
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    for (int nN = 0; nN <= 15; nN++)
                                    {
                                        if (PieceRecupereNoir[nN] == 0)
                                        {
                                            PieceRecupereNoir[nN] = PiecesPourIci[i];
                                            PieceRecupereParNoir.transform.GetChild(0).GetChild(nN).GetChild(PieceRecupereNoir[nN] - 1).gameObject.SetActive(true);
                                            break;
                                        }
                                    }
                                }
                            }

                            PiecesPourIci[i] = PiecesPourIci[PreviousSlot];

                            PieceSurCase.transform.GetChild(0).GetChild(PreviousSlot).GetChild(PiecesPourIci[PreviousSlot] - 1).GetComponent<Renderer>().material.color = CouleurPiece;
                            PieceSurCase.transform.GetChild(0).GetChild(PreviousSlot).GetChild(PiecesPourIci[PreviousSlot] - 1).gameObject.SetActive(false);
                            PiecesPourIci[PreviousSlot] = 0;
                            PieceSurCase.transform.GetChild(0).GetChild(i).GetChild(PiecesPourIci[i] - 1).gameObject.SetActive(true);

                            if (CurrentPlayer == 0 && PiecesPourIci[i] == 1 && i >= 56 && i <= 63)
                            {
                                int oldnB = 0;
                                for (int nB = 0; nB <= 15; nB++)
                                {
                                    if (PieceRecupereNoir[nB] > PieceRecupereNoir[oldnB])
                                    {
                                        oldnB = nB;
                                    }
                                }
                                if (PieceRecupereNoir[oldnB] != 0)
                                {
                                    PieceRecupereParNoir.transform.GetChild(0).GetChild(oldnB).GetChild(PieceRecupereNoir[oldnB] - 1).gameObject.SetActive(false);
                                    PiecesPourIci[i] = PieceRecupereNoir[oldnB];
                                    PieceRecupereNoir[oldnB] = 0;
                                    PieceSurCase.transform.GetChild(0).GetChild(i).GetChild(PiecesPourIci[i] - 1).gameObject.SetActive(true);
                                }
                            }

                            if (CurrentPlayer == 1 && PiecesPourIci[i] == 7 && i >= 0 && i <= 7)
                            {
                                int oldnN = 0;
                                for (int nN = 0; nN <= 15; nN++)
                                {
                                    if (PieceRecupereBlanc[nN] > PieceRecupereBlanc[oldnN])
                                    {
                                        oldnN = nN;
                                    }
                                }
                                if (PieceRecupereBlanc[oldnN] != 0)
                                {
                                    PieceRecupereParBlanc.transform.GetChild(0).GetChild(oldnN).GetChild(PieceRecupereBlanc[oldnN] - 1).gameObject.SetActive(false);
                                    PiecesPourIci[i] = PieceRecupereBlanc[oldnN];
                                    PieceRecupereBlanc[oldnN] = 0;
                                    PieceSurCase.transform.GetChild(0).GetChild(i).GetChild(PiecesPourIci[i] - 1).gameObject.SetActive(true);
                                }
                                
                            }
                            SecondCase = i;
                            PremiereSelection = true;
                            FinCoup = true;
                            GameObject.Find("/Canvas").GetComponent<JoueurEnCours>().FinCoup = true;
                            break;
                        }
                    }
                }
            }
        }
        if (ChangePosition)
        {
            PieceSurCase.transform.GetChild(0).GetChild(FirstCaseValid).GetChild(PiecesPourIci[FirstCaseValid] - 1).gameObject.SetActive(false);

            if (PiecesPourIci[SecondCaseValid] != 0)
            {
                PieceSurCase.transform.GetChild(0).GetChild(SecondCaseValid).GetChild(PiecesPourIci[SecondCaseValid] - 1).gameObject.SetActive(false);
                if (PiecesPourIci[SecondCaseValid] <= 6)
                {
                    for (int nB = 0; nB <= 15; nB++)
                    {
                        if (PieceRecupereBlanc[nB] == 0)
                        {
                            PieceRecupereBlanc[nB] = PiecesPourIci[SecondCaseValid];
                            PieceRecupereParBlanc.transform.GetChild(0).GetChild(nB).GetChild(PieceRecupereBlanc[nB] - 1).gameObject.SetActive(true);
                            break;
                        }
                    }
                }
                else
                {
                    for (int nN = 0; nN <= 15; nN++)
                    {
                        if (PieceRecupereNoir[nN] == 0)
                        {
                            PieceRecupereNoir[nN] = PiecesPourIci[SecondCaseValid];
                            PieceRecupereParNoir.transform.GetChild(0).GetChild(nN).GetChild(PieceRecupereNoir[nN] - 1).gameObject.SetActive(true);
                            break;
                        }
                    }
                }
            }

            PiecesPourIci[SecondCaseValid] = PiecesPourIci[FirstCaseValid];
            PiecesPourIci[FirstCaseValid] = 0;

            PieceSurCase.transform.GetChild(0).GetChild(SecondCaseValid).GetChild(PiecesPourIci[SecondCaseValid] - 1).gameObject.SetActive(true);
            FinCoup = true;
            GameObject.Find("/Canvas").GetComponent<JoueurEnCours>().FinCoup = true;
            ChangePosition = false;
        }
    }
}
Voici le script qui dis qui doit jouer :

Code : Tout sélectionner

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class JoueurEnCours : MonoBehaviour {
    public int CurrentJoueur = 0;
    public bool FinCoup;
    private float TempsBlanc = 0;
    private float TempsNoir = 0;
    private string minutesBlanc;
    private string secondsBlanc;
    private string minutesNoir;
    private string secondsNoir;

    void Start ()
    {
        transform.GetChild(CurrentJoueur).gameObject.SetActive(true);
        transform.GetChild(Mathf.Abs(CurrentJoueur - 1)).gameObject.SetActive(false);
        minutesBlanc = "00";
        secondsBlanc = "00";
        minutesNoir = "00";
        secondsNoir = "00";
    }

    // Update is called once per frame
    void Update () {
        if (CurrentJoueur == 0)
        {
            TempsBlanc += Time.deltaTime;
            float minutesB = Mathf.Floor(TempsBlanc / 60);
            float secondsB = Mathf.RoundToInt(TempsBlanc % 60);
            if (minutesB < 10)
            {
                minutesBlanc = "0" + minutesB.ToString();
            }
            else
            {
                minutesBlanc = minutesB.ToString();
            }
            if (secondsB < 10)
            {
                secondsBlanc = "0" + Mathf.RoundToInt(secondsB).ToString();
            }
            else
            {
                secondsBlanc = secondsB.ToString();
            }
        }
        if (CurrentJoueur == 1)
        {
            TempsNoir += Time.deltaTime;
            float minutesN = Mathf.Floor(TempsNoir / 60);
            float secondsN = Mathf.RoundToInt(TempsNoir % 60);
            if (minutesN < 10)
            {
                minutesNoir = "0" + minutesN.ToString();
            }
            else
            {
                minutesNoir = minutesN.ToString();
            }
            if (secondsN < 10)
            {
                secondsNoir = "0" + Mathf.RoundToInt(secondsN).ToString();
            }
            else
            {
                secondsNoir = secondsN.ToString();
            }
        }
        transform.GetChild(2).GetChild(0).gameObject.GetComponent<UnityEngine.UI.Text>().text = "White Player Time : " + minutesBlanc + "  : " + secondsBlanc + "\n \n" + "Black Player Time : " + minutesNoir + "  : " + secondsNoir;
        if (FinCoup)
        {
            transform.GetChild(CurrentJoueur).gameObject.SetActive(false);
            transform.GetChild(Mathf.Abs(CurrentJoueur - 1)).gameObject.SetActive(true);
            CurrentJoueur = Mathf.Abs(CurrentJoueur - 1);
            FinCoup = false;
        }
    }
}
J'ai créé un ensemble de jeux :

Un HUB : https://bit.ly/2J6EZTO
Un jeu avec contrôle tactile à l'écran : https://bit.ly/2J3IkTw
Un jeu en VR : https://bit.ly/2h5jdzk
Un jeu en AR : https://bit.ly/2LgMvIo

Il s'agit de FPS pour Android.

Avatar de l’utilisateur
boubouk50
ModoGenereux
ModoGenereux
Messages : 6216
Inscription : 28 Avr 2014 11:57
Localisation : Saint-Didier-en-Bresse (71)

Re: [DB-AL] Jeux multijoueur simple.

Message par boubouk50 » 23 Avr 2018 09:03

Merci Paullux pour toutes ces infos et désolé de ne pas toujours pouvoir te répondre.
j'ai un peu l'impression que tu te réponds souvent tout seul. Piètre entraide que nous faisons... En tout cas merci de nous apporter tes réponses! :super:
"Ce n'est pas en améliorant la bougie, que l'on a inventé l'ampoule, c'est en marchant longtemps."
Nétiquette du forum
Savoir faire une recherche
Apprendre la programmation

Répondre

Revenir vers « Développement plateformes mobile Iphone et Android »