public void AssignPlayerToSlot(BattlecarsPlayerNet _player, bool _left, int _slotID) { // Get the current slot list depending on the left param List <LobbyPlayerSlot> slots = _left ? leftTeamSlots : rightTeamSlots; // Assign the player to the releant slot in the list slots[_slotID].AssignPlayer(_player); }
public void AssignPlayerToLobbySlot(BattlecarsPlayerNet _player, bool _left, int _slotId) { // Get the correct slot list depending on the left param. List <LobbyPlayerSlot> slots = _left ? leftTeamSlots : rightTeamSlots; // Assign the player to the relevant slot in this list. slots[_slotId].AssignPlayer(_player); }
public void OnPlayerConnected(BattlecarsPlayerNet _player) { bool assigned = false; List <LobbyPlayerSlot> slots = assigningToLeft ? leftTeamSlots : rightTeamSlots; if (_player.isLocalPlayer) { localPlayer = _player; } //TRUE POWER OF LAMBDAS //Loop through each item in the list and run a lambda with the item at that index. slots.ForEach(slot => { if (assigned) { return; } else if (!slot.isTaken) { //If we haven't already assigned the player to a slot and this slot hasn't been taken, //assign this player to this slot and team //as slot has been assigned slot.AssignPlayer(_player); assigned = true; //Which slot is this? //Get the correct slot index and tell the server to set the slot on every client int slotId = slots.IndexOf(slot); localPlayer.AssignPlayerToSlot(assigningToLeft, slotId, _player.playerId); } }); for (int i = 0; i < leftTeamSlots.Count; i++) { LobbyPlayerSlot slot = leftTeamSlots[i]; if (slot.isTaken) { localPlayer.AssignPlayerToSlot(slot.isLeft, i, slot.Player.playerId); } } for (int i = 0; i < rightTeamSlots.Count; i++) { LobbyPlayerSlot slot = rightTeamSlots[i]; if (slot.isTaken) { localPlayer.AssignPlayerToSlot(slot.isLeft, i, slot.Player.playerId); } } //Flip the flag so that the next one will end up in the other list. assigningToLeft = !assigningToLeft; }
public void OnPlayerConnected(BattlecarsPlayerNet _player) { bool assigned = false; //If the player is the localPlayer, assign it. if (_player.isLocalPlayer) { localPlayer = _player; } List <LobbyPlayerSlot> slots = assigningToLeft ? leftTeamSlots : rightTeamSlots; //Loop through and run a lambda with the item at the index slots.ForEach(slot => { //If we have assigned the value already, return from the lambda if (assigned) { return; //This is break within a lambda break. There is no break in lambda looop. } else if (!slot.IsTaken) { //If we haven't already assigned the player to a sllot and this slot havent been //taken, then assign the player to this slot and flag as the slot been assigned. slot.AssignPlayer(_player); slot.SetSide(assigningToLeft); assigned = true; } }); for (int i = 0; i < leftTeamSlots.Count; i++) { LobbyPlayerSlot slot = leftTeamSlots[i]; if (slot.IsTaken) { localPlayer.AssignPlayerToSlot(slot.IsLeft, i, slot.Player.playerID); } } for (int i = 0; i < rightTeamSlots.Count; i++) { LobbyPlayerSlot slot = rightTeamSlots[i]; if (slot.IsTaken) { localPlayer.AssignPlayerToSlot(slot.IsLeft, i, slot.Player.playerID); } } //Flip the flag so that the next one will end up in the other list. assigningToLeft = !assigningToLeft; }
public void OnPlayerConnected(BattlecarsPlayerNet _player) { bool assigned = false; // If the player is the localPlayer, assign it. if (_player.isLocalPlayer) { localPlayer = _player; } List <LobbyPlayerSlot> slots = assigningToLeft ? leftTeamSlots : rightTeamSlots; // Loop through each item in the list and run a lambda w/ the item at that index. slots.ForEach(slot => { if (assigned) { return; } else if (!slot.IsTaken) { slot.AssignPlayer(_player); slot.SetSide(assigningToLeft); assigned = true; } }); for (int i = 0; i < leftTeamSlots.Count; i++) { LobbyPlayerSlot slot = leftTeamSlots[i]; if (slot.IsTaken) { localPlayer.AssignPlayerToSlot(slot.IsLeft, i, slot.Player.playerId); } } for (int i = 0; i < rightTeamSlots.Count; i++) { LobbyPlayerSlot slot = rightTeamSlots[i]; if (slot.IsTaken) { localPlayer.AssignPlayerToSlot(slot.IsLeft, i, slot.Player.playerId); } } // Flip the flag so that the next one will end up in the other list. assigningToLeft = !assigningToLeft; }
// Set the player in this slot to the passed player public void AssignPlayer(BattlecarsPlayerNet _player) => player = _player;