/// <summary> /// Adds a <see cref="PlayerItem"/> to a team /// </summary> /// <param name="item">item</param> /// <param name="team">team, or null for a new team</param> private void addPlayerToTeam(PlayerItem[] item, TeamItem team) { // Find the right team, if target-team is null if (team == null) { int items = SimulatorConfiguration.PLAYERLIMIT + 1; // If team is null, search for empty team for (int i = 0; i < config.teams.Length; i++) { if (config.teams[i].Players.Count < items) { team = config.teams[i]; items = team.Players.Count; } } // If there are no more empty teams, use the last one if (team == null) { team = config.teams[config.teams.Length - 1]; } } // Find out, how many players are enabled int activePlayers = 0; for (int i = 0; i < config.teams.Length; i++) { activePlayers += config.teams[i].Players.Count; } // Add to playerlist for (int i = 0; i < item.Length; i++) { if (activePlayers >= SimulatorConfiguration.PLAYERLIMIT) { break; } team.Players.Add(item[i]); activePlayers++; } UpdatePanel(); }
private void bubbleTeams() { int gap = 0; for (int i = 0; i < config.teams.Length; i++) { if (config.teams[i].Players.Count == 0) { gap++; } else if (config.teams[i - gap].Players.Count == 0) { TeamItem lower = config.teams[i - gap]; TeamItem current = config.teams[i]; lower.Players.AddRange(current.Players); current.Players.Clear(); } } }