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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. {
  17. int score = 0;
  18. foreach (var player in playerList)
  19. score += (int)player.Score;
  20. return score;
  21. }
  22. }
  23. public Character? GetPlayer(long ID)
  24. {
  25. foreach (Character player in playerList)
  26. {
  27. if (player.ID == ID)
  28. {
  29. return player;
  30. }
  31. }
  32. return null;
  33. }
  34. public void AddPlayer(Character player)
  35. {
  36. playerList.Add(player);
  37. }
  38. public void OutPlayer(long ID)
  39. {
  40. int i;
  41. for (i = 0; i < playerList.Count; ++i)
  42. {
  43. if (playerList[i].ID == ID)
  44. break;
  45. }
  46. playerList.RemoveAt(i);
  47. }
  48. public long[] GetPlayerIDs()
  49. {
  50. long[] playerIDs = new long[playerList.Count];
  51. int num = 0;
  52. foreach (Character player in playerList)
  53. {
  54. playerIDs[num++] = player.ID;
  55. }
  56. return playerIDs;
  57. }
  58. public static bool teamExists(long findTeamID)
  59. {
  60. return findTeamID < currentMaxTeamID;
  61. }
  62. public Team()
  63. {
  64. teamID = currentMaxTeamID++;
  65. playerList = new List<Character>();
  66. }
  67. }
  68. }