public Player(Team team, String name, float maxSpeed, int visibleId) { PlayerTeam = team; Name = name; MaxSpeed = maxSpeed; VisibleID = visibleId; UniqueId = NextUniqueId++; }
/// <summary> /// So that we can add players with unique ids this function can return /// the next free id for a given team. /// </summary> /// <param name="team"></param> /// <returns>0 if there are no players on that team otherwise the first /// free id > 0</returns> public int GetNextFreePlayerId(Team team) { List<int> ids = new List<int>(); foreach (Player player in PlayerMovement.Keys.Where(player => player.PlayerTeam == team)) { ids.Add(player.VisibleID); } ids.Sort(); int nextFreeId = 1; int prevId = 0; foreach (int id in ids) { if (id - prevId > 1) { nextFreeId = prevId + 1; break; } else { nextFreeId = id + 1; prevId = id; } } return nextFreeId; }