LocalGamerCollection.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Collections.ObjectModel;
  2. namespace Microsoft.Xna.Framework.Net
  3. {
  4. /// <summary>
  5. /// Collection of local network gamers in a session.
  6. /// </summary>
  7. public class LocalGamerCollection : ReadOnlyCollection<LocalNetworkGamer>
  8. {
  9. internal LocalGamerCollection(IList<LocalNetworkGamer> list) : base(list) { }
  10. /// <summary>
  11. /// Finds a local gamer by their ID.
  12. /// </summary>
  13. /// <param name="id">The ID to search for.</param>
  14. /// <returns>The local gamer with the specified ID, or null if not found.</returns>
  15. public LocalNetworkGamer FindGamerById(string id)
  16. {
  17. foreach (var gamer in this)
  18. {
  19. if (gamer.Id == id)
  20. return gamer;
  21. }
  22. return null;
  23. }
  24. /// <summary>
  25. /// Gets the host gamer of the session (if local).
  26. /// </summary>
  27. public LocalNetworkGamer Host
  28. {
  29. get
  30. {
  31. foreach (var gamer in this)
  32. {
  33. if (gamer.IsHost)
  34. return gamer;
  35. }
  36. return null;
  37. }
  38. }
  39. }
  40. }