Advertisement
leo1553

DeckManager

Sep 6th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. Card[] cards;
  2. public int Count { get; private set; }
  3.  
  4. public void Shuffle() {
  5. List<Card> deck = new List<Card>();
  6. int i, x;
  7. for(i = 0; i < Count; i++)
  8. deck.Add(cards[i]);
  9.  
  10. for(i = 0; i < Count; i++) {
  11. x = rand.Next(deck.Count);
  12. cards[i] = deck[x];
  13. deck.RemoveAt(x);
  14. }
  15. }
  16.  
  17. public void AddOnTop(Card card) {
  18. cards[Count++] = card;
  19. }
  20.  
  21. public void AddOnBottom(Card card) {
  22. for(int i = Count; i > 0; i--)
  23. cards[i] = cards[i - 1];
  24. Count++;
  25. cards[0] = card;
  26. }
  27.  
  28. public void AddRandom(Card card) {
  29. int x = rand.Next(Count);
  30. for(int i = Count; i > x; i--)
  31. cards[i] = cards[i - 1];
  32. Count++;
  33. cards[x] = card;
  34. }
  35.  
  36. public Card RemoveFromTop() {
  37. return cards[--Count];
  38. }
  39.  
  40. public Card RemoveFromBotton() {
  41. Card r = cards[0];
  42. for(int i = 1; i < Count; i++)
  43. cards[i - 1] = cards[i];
  44. Count--;
  45. return r;
  46. }
  47.  
  48. public Card RemoveRandom() {
  49. int x = rand.Next(Count);
  50. Card r = cards[x];
  51. for(int i = x + 1; i < Count; i++)
  52. cards[i - 1] = cards[i];
  53. Count--;
  54. return r;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement