Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.87 KB | None | 0 0
  1. /**
  2.  * Card.java
  3.  *
  4.  * @brief A class that represents a playing card
  5.  *
  6.  * @details
  7.  * This class is responsible for storing, printing and comparing a playing card.
  8.  */
  9.  
  10. class Card {
  11.  
  12.   // Suit enumeration
  13.   public enum Suit
  14.   {
  15.     SPADES,
  16.     HEARTS,
  17.     DIAMONDS,
  18.     CLUBS
  19.   }
  20.  
  21.   // Value enumeration
  22.   public enum Value
  23.   {
  24.     JOKER,
  25.     ACE,
  26.     TWO,
  27.     THREE,
  28.     FOUR,
  29.     FIVE,
  30.     SIX,
  31.     SEVEN,
  32.     EIGHT,
  33.     NINE,
  34.     TEN,
  35.     JACK,
  36.     QUEEN,
  37.     KING
  38.   }
  39.  
  40.   // Constructor
  41.   public Card()
  42.   {}
  43.  
  44.   // Returns the suit of the card.
  45.     //
  46.     // @return  The suit.
  47.   public Suit get_suit()
  48.   {
  49.     return m_suit;
  50.   }
  51.  
  52.   // Returns the value of the card.
  53.     //
  54.     // @return  The suit enumeration.
  55.   public Value get_value()
  56.   {
  57.     return m_value;
  58.   }
  59.  
  60.   // Compares if the card face value of two cards are equal.  
  61.   // Does not take suit into consideration.
  62.   //
  63.   // @param[in] rhs   The right hand side card.
  64.   // @return    true if equal.
  65.   public boolean is_equal( Card rhs )
  66.   {
  67.     return m_value.ordinal() == rhs.m_value.ordinal();
  68.   }
  69.  
  70.   // Compares if the card face value of the left card is less than the right.  
  71.   // Does not take suit into consideration.
  72.   //
  73.   // @param[in] rhs   The right hand side card.
  74.   // @return    true if less than.
  75.   public boolean is_less_than( Card rhs )
  76.   {
  77.     return m_value.ordinal() < rhs.m_value.ordinal();
  78.   }
  79.  
  80.   // Compares if the card face value of the left card is less than or equal the right.  
  81.   // Does not take suit into consideration.
  82.   //
  83.   // @param[in] rhs   The right hand side card.
  84.   // @return    true if less than or equal.
  85.   public boolean is_less_than_or_equal( Card rhs )
  86.   {
  87.     return m_value.ordinal() <= rhs.m_value.ordinal();
  88.   }
  89.  
  90.   // Compares if the card face value of the left card is greater than the right.  
  91.   // Does not take suit into consideration.
  92.   //
  93.   // @param[in] rhs   The right hand side card.
  94.   // @return    true if greater than.
  95.   public boolean is_greater_than( Card rhs )
  96.   {
  97.     return m_value.ordinal() > rhs.m_value.ordinal();
  98.   }
  99.  
  100.   // Compares if the card face value of the left card is greater than or equal the right.  
  101.   // Does not take suit into consideration.
  102.   //
  103.   // @param[in] rhs   The right hand side card.
  104.   // @return    true if greater than or equal.
  105.   public boolean is_greater_than_or_equal( Card rhs )
  106.   {
  107.     return m_value.ordinal() >= rhs.m_value.ordinal();
  108.   }
  109.  
  110.   // Prints a single card to std out.
  111.   public void print()
  112.   {
  113.     System.out.print(card_array[m_suit.ordinal()][m_value.ordinal()]);
  114.   }
  115.  
  116.   // Sets the value of the card.
  117.     //
  118.     // @param[in]   value The value of the card.
  119.     // @param[in]   suit  The value of thd card.
  120.   public void set_value(Value value, Suit suit)
  121.   {
  122.     m_value = value;
  123.     m_suit = suit;
  124.   }
  125.  
  126.   public void set_value(int value, int suit)
  127.   {
  128.     m_value = Value.values()[value];
  129.     m_suit = Suit.values()[suit];
  130.   }
  131.  
  132.  
  133.   private static String card_array[][] = {{"[JKR]",
  134.                                     "[ A\u2660]",
  135.                                     "[ 2\u2660]",
  136.                                     "[ 3\u2660]",
  137.                                     "[ 4\u2660]",
  138.                                     "[ 5\u2660]",
  139.                                     "[ 9\u2660]",
  140.                                     "[ 7\u2660]",
  141.                                     "[ 8\u2660]",
  142.                                     "[ 9\u2660]",
  143.                                     "[10\u2660]",
  144.                                     "[ J\u2660]",
  145.                                     "[ Q\u2660]",
  146.                                     "[ K\u2660]"
  147.                                   },{"[JKR]",
  148.                                     "[ A\u2665]",
  149.                                     "[ 2\u2665]",
  150.                                     "[ 3\u2665]",
  151.                                     "[ 4\u2665]",
  152.                                     "[ 5\u2665]",
  153.                                     "[ 6\u2665]",
  154.                                     "[ 7\u2665]",
  155.                                     "[ 8\u2665]",
  156.                                     "[ 9\u2665]",
  157.                                     "[10\u2665]",
  158.                                     "[ J\u2665]",
  159.                                     "[ Q\u2665]",
  160.                                     "[ K\u2665]"
  161.                                   },{"[JKR]",
  162.                                     "[ A\u2666]",
  163.                                     "[ 2\u2666]",
  164.                                     "[ 3\u2666]",
  165.                                     "[ 4\u2666]",
  166.                                     "[ 5\u2666]",
  167.                                     "[ 6\u2666]",
  168.                                     "[ 7\u2666]",
  169.                                     "[ 8\u2666]",
  170.                                     "[ 9\u2666]",
  171.                                     "[10\u2666]",
  172.                                     "[ J\u2666]",
  173.                                     "[ Q\u2666]",
  174.                                     "[ K\u2666]"
  175.                                   },{"[JKR]",
  176.                                     "[ A\u2663]",
  177.                                     "[ 2\u2663]",
  178.                                     "[ 3\u2663]",
  179.                                     "[ 4\u2663]",
  180.                                     "[ 5\u2663]",
  181.                                     "[ 6\u2663]",
  182.                                     "[ 7\u2663]",
  183.                                     "[ 8\u2663]",
  184.                                     "[ 9\u2663]",
  185.                                     "[10\u2665]",
  186.                                     "[ J\u2663]",
  187.                                     "[ Q\u2663]",
  188.                                     "[ K\u2663]"}};
  189.  
  190.   private Suit m_suit;  // The suit of the card
  191.   private Value m_value;  // The value of the card
  192.  
  193.  
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement