public void AddPlayer(BattlecarsPlayerNet _player)
 {
     if (!players.ContainsKey(_player.playerID))
     {
         players.Add(_player.playerID, _player);
     }
 }
        private IEnumerator AssignPlayerToLobbySlotDelayed(BattlecarsPlayerNet _player, bool _left, int _slotId)
        {
            Lobby lob = FindObjectOfType <Lobby>();

            while (lob == null)
            {
                yield return(null);

                lob = FindObjectOfType <Lobby>();
            }

            //Lobby successfully got, so assign the player
            lob.AssignPlayerToLobbySlot(_player, _left, _slotId);
        }
Ejemplo n.º 3
0
        private IEnumerator AssignPlayerToLobbySlotDelayed(BattlecarsPlayerNet _player, bool _left, int _slotId)
        {
            // Keep trying to get the lobby until it's not null.
            Lobby lobby = FindObjectOfType <Lobby>();

            while (lobby == null)
            {
                yield return(null);

                lobby = FindObjectOfType <Lobby>();
            }

            // Lobby successfully got, so assign the player.
            lobby.AssignPlayerToLobbySlot(_player, _left, _slotId);
        }
        protected void AssignPlayerId(GameObject _player)
        {
            byte        id        = 0;
            List <byte> playerIDs = players.Keys.OrderBy(x => x).ToList();

            //List<byte> = players.Keys.byte(x => x).ToList();

            foreach (byte key in playerIDs)
            {
                if (id == key)
                {
                    id++;
                }
            }

            //Get the playernet componn==t from the gameobject and asssign its plkayed
            BattlecarsPlayerNet player = _player.GetComponent <BattlecarsPlayerNet>();

            player.playerID = id;
            players.Add(id, player);
        }
Ejemplo n.º 5
0
        protected void AssignPlayerId(GameObject _playerObj)
        {
            byte id = 0;
            // Generate a list that is sorted by key's value.
            List <byte> playerIDs = players.Keys.OrderBy(x => x).ToList();

            // Loop through all keys in the previous list, and assign the id.
            foreach (byte key in playerIDs)
            {
                if (id == key)
                {
                    id++;
                }
            }

            // Get the playerNet component from the gameObject and assign it's playerId.
            BattlecarsPlayerNet player = _playerObj.GetComponent <BattlecarsPlayerNet>();

            player.playerId = id;
            players.Add(id, player);
        }
Ejemplo n.º 6
0
        protected void AssignPlayerId(GameObject _playerObj)
        {
            byte id = 0;
            //List<string> playerUsernames = players.Values.Select(x => x.username).ToList();
            // Generate a list that is sorted by the keys value
            List <byte> playerIds = players.Keys.OrderBy(x => x).ToList();

            // Loop through all keys (playerID's) in the player dictionary
            foreach (byte key in playerIds)
            {
                // If the temp id matches this key, increment the id value
                if (id == key)
                {
                    id++;
                }
            }

            // Get the playernet component from the gameobject and assign it's playerid
            BattlecarsPlayerNet player = _playerObj.GetComponent <BattlecarsPlayerNet>();

            player.playerId = id;
            players.Add(id, player);
        }
        protected void AssignPlayerID(GameObject _playerObj)
        {
            //Find available ID in the players dictionary = loop through all keys (playerId) and increment
            byte id = 0;

            //Taken all the keys and sorted them in a sequential list. (System.Linq)
            //Use sparingly because although powerful, is slow
            List <byte> playerIds = players.Keys.OrderBy(x => x).ToList();

            foreach (byte key in playerIds)
            {
                if (id == key)
                {
                    id++;
                }
            }

            //Get the playernet component from the go and assign id
            BattlecarsPlayerNet player = _playerObj.GetComponent <BattlecarsPlayerNet>();

            player.playerId = id;
            players.Add(id, player); //add to dictionary
        }