Advertisement
Guest User

hand.cs

a guest
Oct 15th, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Diagnostics;
  7.  
  8. namespace SharedGamesClasses {
  9.  
  10. public class Hand : IEnumerable {
  11. // IEnumerable allows code in other classes to use foreach with this class, e.g.
  12. // Hand myHand;
  13. // ...
  14. // foreach (Card card in myHand) {
  15. // ...
  16. // }
  17. // The precise details of IEnumerable are unimportant for this assignment.
  18.  
  19. private List<Card> cards;
  20.  
  21. /// <summary>
  22. /// Constructor - creates a Hand object that is empty (initially).
  23. /// </summary>
  24. public Hand() {
  25. cards = new List<Card>();
  26. }
  27.  
  28. /// <summary>
  29. /// Constructor - creates a Hand object from a List of cards.
  30. /// </summary>
  31. public Hand(List<Card> cards) {
  32. this.cards = cards;
  33. }
  34.  
  35. /// <summary>
  36. /// </summary>
  37. /// <returns>The number of cards in the hand.</returns>
  38. public int GetCount() {
  39. return cards.Count;
  40. }
  41.  
  42. /// <summary>
  43. /// Gets the card at a given position, without removing it from the hand.
  44. /// </summary>
  45. /// <param name="index"></param>
  46. /// <returns>the card at a given position</returns>
  47. public Card GetCard(int index) {
  48. return cards[index];
  49. }
  50.  
  51. /// <summary>
  52. /// Adds a card to the Hand.
  53. /// </summary>
  54. /// <param name="card"></param>
  55. public void Add(Card card) {
  56. cards.Add(card);
  57. }
  58.  
  59. /// <summary>
  60. /// Tests whether the Hand contains a given Card.
  61. /// </summary>
  62. /// <param name="card"></param>
  63. /// <returns>True if the card is found in the Hand; otherwise, False.
  64. /// </returns>
  65. public bool Contains(Card card) {
  66. return cards.Contains(card);
  67. }
  68.  
  69. /// <summary>
  70. /// Removes a given Card from the Hand, if it exists in the Hand.
  71. /// </summary>
  72. /// <param name="card"></param>
  73. /// <returns>True if the card is found and removed; otherwise, False.
  74. /// </returns>
  75. public bool Remove(Card card) {
  76. return cards.Remove(card);
  77. }
  78.  
  79. /// <summary>
  80. /// Removes a Card from the specified position in the Hand.
  81. /// </summary>
  82. /// <param name="index">The zero-based index of the element to remove.</param>
  83. public void RemoveAt(int index) {
  84. cards.RemoveAt(index);
  85. }
  86.  
  87. /// <summary>
  88. /// Sorts the cards in the Hand.
  89. /// </summary>
  90. public void Sort() {
  91. cards.Sort();
  92. }
  93.  
  94. /// <summary>
  95. /// Outputs the hand of cards.
  96. /// See the ToString method in the Card class for a description of
  97. /// the two parameters: shortFormat and displaySuit.
  98. /// Pre: true
  99. /// Post: Displayed the hand of cards.
  100. /// </summary>
  101. public void DisplayHand(bool shortFormat, bool displaySuit) {
  102. //
  103. //**************** CODE NEEDS TO BE ADDED**********************
  104. // Should be able to call the ToString method in the Card class,
  105. // as part of this.
  106. //
  107.  
  108. } // end DisplayHand
  109.  
  110. // Needed so that IEnumerable works correctly (see comments near top of the file).
  111. // Do NOT try to call this method directly in your own code.
  112. public IEnumerator GetEnumerator() {
  113. return cards.GetEnumerator();
  114. }
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement