/// <summary> /// Removes a player from the registered players collection. /// </summary> /// <param name="player">The player controller to remove.</param> public static void DropPlayer(SnowmanControl player) { // Search for the player to remove. int indexToRemove = -1; for (int i = 0; i < Players.Length; i++) { if (Players[i] == player) { indexToRemove = i; break; } } // If the sentinel value is found then the caller tried // to remove a player that was never registered. if (indexToRemove == -1) { throw new Exception("Attempted to drop player that was not registered."); } else { // Remove the index of the dropped player. Players = Players.WithIndexRemoved(indexToRemove); // Notify other scripts that a change in player count has occured. PlayersChanged?.Invoke(Players); } }
public virtual async Task RemovePlayerAsync(IPlayer player) { _players.Remove(player); if (PlayersChanged != null) { await PlayersChanged.Invoke(this, Players); } }
protected virtual void OnPlayersChanged() { Debug.WriteLine("OnPlayersChanged called"); PlayersChanged?.Invoke(this, new PlayersEventArgs() { playerList = gameState.players }); }
/// <summary> /// You should probably be using World.MovePlayer in most scenarios to make sure all the correct events are triggered /// </summary> /// <param name="player"></param> /// <returns></returns> public virtual async Task AddPlayerAsync(IPlayer player) { player.Map = this; _players.Add(player); if (PlayersChanged != null) { await PlayersChanged.Invoke(this, Players); } }
/// <summary> /// Adds a new player to the registered players collection. /// </summary> /// <param name="player">The player controller to add.</param> public static void AddPlayer(SnowmanControl player) { // Check to see if the player has already been added. foreach (SnowmanControl existingPlayer in Players) { if (existingPlayer == player) { throw new Exception( "Registered a player when it was already registered to the player service."); } } // Insert the new player to the end of the players collection. SnowmanControl[] players = Players; Array.Resize(ref players, players.Length + 1); players[players.Length - 1] = player; Players = players; // Notify other scripts that a change in player count has occured. PlayersChanged?.Invoke(Players); }