You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Team.cs 1.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Collections.Generic;
  2. namespace GameClass.GameObj
  3. {
  4. public class Team
  5. {
  6. private static long currentMaxTeamID = 0;
  7. public static long CurrentMaxTeamID => currentMaxTeamID;
  8. private readonly long teamID;
  9. public long TeamID => teamID;
  10. public const long invalidTeamID = long.MaxValue;
  11. public const long noneTeamID = long.MinValue;
  12. private readonly List<Character> playerList;
  13. public int Score
  14. {
  15. get {
  16. int score = 0;
  17. foreach (var player in playerList)
  18. score += player.Score;
  19. return score;
  20. }
  21. }
  22. public Character? GetPlayer(long ID)
  23. {
  24. foreach (Character player in playerList)
  25. {
  26. if (player.ID == ID)
  27. {
  28. return player;
  29. }
  30. }
  31. return null;
  32. }
  33. public void AddPlayer(Character player)
  34. {
  35. playerList.Add(player);
  36. }
  37. public void OutPlayer(long ID)
  38. {
  39. int i;
  40. for (i = 0; i < playerList.Count; ++i)
  41. {
  42. if (playerList[i].ID == ID)
  43. break;
  44. }
  45. playerList.RemoveAt(i);
  46. }
  47. public long[] GetPlayerIDs()
  48. {
  49. long[] playerIDs = new long[playerList.Count];
  50. int num = 0;
  51. foreach (Character player in playerList)
  52. {
  53. playerIDs[num++] = player.ID;
  54. }
  55. return playerIDs;
  56. }
  57. public static bool teamExists(long findTeamID)
  58. {
  59. return findTeamID < currentMaxTeamID;
  60. }
  61. public Team()
  62. {
  63. teamID = currentMaxTeamID++;
  64. playerList = new List<Character>();
  65. }
  66. }
  67. }