Advertisement
Guest User

Untitled

a guest
Mar 19th, 2020
1,018
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Guild
  7. {
  8. public class Guild
  9. {
  10. private List<Player> roster;
  11.  
  12. public Guild(string name, int capacity)
  13. {
  14. this.Name = name;
  15. this.Capacity = capacity;
  16. this.roster = new List<Player>();
  17. }
  18.  
  19. public string Name { get; private set; }
  20.  
  21. public int Capacity { get; private set; }
  22.  
  23. public int Count
  24. {
  25. get
  26. {
  27. return this.roster.Count;
  28. }
  29. }
  30.  
  31. public void AddPlayer(Player player)
  32. {
  33. if (roster.Count < this.Capacity && !roster.Any(x => x.Name == player.Name))
  34. {
  35. this.roster.Add(player);
  36. }
  37. }
  38.  
  39. public bool RemovePlayer(string namey)
  40. {
  41. if (roster.Any(x => x.Name == namey))
  42. {
  43. Player myTempPlayer = roster.Where(x => x.Name == namey).FirstOrDefault();
  44. roster.Remove(myTempPlayer);
  45. return true;
  46. }
  47. return false;
  48. }
  49.  
  50. public void PromotePlayer(string namePromotedPlayer)
  51. {
  52. if (roster.Any(x => x.Name == namePromotedPlayer))
  53. {
  54. Player myPromotedPlayer = roster.Where(x => x.Name == namePromotedPlayer).FirstOrDefault();
  55. myPromotedPlayer.Rank = "Member";
  56. }
  57. }
  58.  
  59. public void DemotePlayer(string nameDemotedPlayer)
  60. {
  61. if (roster.Any(x => x.Name == nameDemotedPlayer))
  62. {
  63. Player myDemotedPlayer = roster.Where(x => x.Name == nameDemotedPlayer).FirstOrDefault();
  64. myDemotedPlayer.Rank = "Trial";
  65. }
  66. }
  67.  
  68. public string Report()
  69. {
  70. StringBuilder myString = new StringBuilder();
  71. myString.AppendLine($"Players in the guild: {this.Name}");
  72. foreach (var player in this.roster)
  73. {
  74. myString.AppendLine($"Player {player.Name}: {player.Classs}");
  75. myString.AppendLine($"Rank: {player.Rank}");
  76. myString.AppendLine($"Description: {player.Description}");
  77. }
  78. return myString.ToString().TrimEnd();
  79. }
  80.  
  81. public Player[] KickPlayersByClass(string classy)
  82. {
  83.  
  84. List<Player> myListTemp = new List<Player>();
  85. foreach (var player in this.roster)
  86. {
  87. if (player.Classs == classy)
  88. {
  89. myListTemp.Add(player);
  90. }
  91. }
  92. Player[] myArrayToReturn = myListTemp.ToArray();
  93.  
  94. this.roster = this.roster.Where(x => x.Classs != classy).ToList();
  95.  
  96. return myArrayToReturn;
  97. }
  98. }
  99. }
Advertisement
RAW Paste Data Copied
Advertisement