Slowhand-VI

TUT: blackjack_card.fos

Jan 19th, 2016
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.38 KB | None | 0 0
  1. /**<
  2.  *  Card class for Blackjack.
  3.  */
  4.  
  5. #define CARD_SUIT_NONE                  (0)
  6. #define CARD_SUIT_SPADES                (1)
  7. #define CARD_SUIT_HEARTS                (2)
  8. #define CARD_SUIT_DIAMONDS              (3)
  9. #define CARD_SUIT_CLUBS                 (4)
  10.  
  11. #define CARD_TYPE_NONE                  (0)
  12. #define CARD_TYPE_ACE                   (1)
  13. #define CARD_TYPE_TWO                   (2)
  14. #define CARD_TYPE_THREE                 (3)
  15. #define CARD_TYPE_FOUR                  (4)
  16. #define CARD_TYPE_FIVE                  (5)
  17. #define CARD_TYPE_SIX                   (6)
  18. #define CARD_TYPE_SEVEN                 (7)
  19. #define CARD_TYPE_EIGHT                 (8)
  20. #define CARD_TYPE_NINE                  (9)
  21. #define CARD_TYPE_TEN                   (10)
  22. #define CARD_TYPE_JACK                  (11)
  23. #define CARD_TYPE_QUEEN                 (12)
  24. #define CARD_TYPE_KING                  (13)
  25.  
  26. #define CARD_COLOR_NONE                 (0)
  27. #define CARD_COLOR_RED                  (1)
  28. #define CARD_COLOR_BLACK                (2)
  29.  
  30. class CCard
  31. {
  32.     private uint8 type;
  33.     private uint8 suit;
  34.  
  35.     uint8 Type()    {   return type;    }
  36.     uint8 Suit()    {   return suit;    }
  37.     uint8 Color()
  38.     {
  39.         switch (suit)
  40.         {
  41.  
  42.             case CARD_SUIT_HEARTS:
  43.             case CARD_SUIT_DIAMONDS:
  44.                 return CARD_COLOR_RED;
  45.             case CARD_SUIT_CLUBS:
  46.             case CARD_SUIT_SPADES:
  47.                 return CARD_COLOR_BLACK;
  48.         }
  49.         return CARD_COLOR_NONE;
  50.     }
  51.     uint8 Value()
  52.     {
  53.         switch (type)
  54.         {
  55.             case CARD_TYPE_ACE:
  56.                 return 11;
  57.             case CARD_TYPE_TWO:
  58.                 return 2;
  59.             case CARD_TYPE_THREE:
  60.                 return 3;
  61.             case CARD_TYPE_FOUR:
  62.                 return 4;
  63.             case CARD_TYPE_FIVE:
  64.                 return 5;
  65.             case CARD_TYPE_SIX:
  66.                 return 6;
  67.             case CARD_TYPE_SEVEN:
  68.                 return 7;
  69.             case CARD_TYPE_EIGHT:
  70.                 return 8;
  71.             case CARD_TYPE_NINE:
  72.                 return 9;
  73.             case CARD_TYPE_TEN:
  74.             case CARD_TYPE_JACK:
  75.             case CARD_TYPE_QUEEN:
  76.             case CARD_TYPE_KING:
  77.                 return 10;
  78.         }
  79.         return 0;
  80.     }
  81.  
  82.  
  83.     CCard(uint8 cardType, uint8 cardSuit)
  84.     {
  85.         type = cardType;
  86.         suit = cardSuit;
  87.     }
  88.  
  89.     string GetCardNotation()
  90.     {
  91.         string notation = "";
  92. //        switch (suit)
  93. //        {
  94. //            case CARD_SUIT_SPADES:
  95. //                notation = "s";         //  ASCII: ALT + 6
  96. //                break;
  97. //            case CARD_SUIT_HEARTS:
  98. //                notation = "h";         //  ASCII: ALT + 3
  99. //                break;
  100. //            case CARD_SUIT_DIAMONDS:
  101. //                notation = "d";         //  ASCII: ALT + 4
  102. //                break;
  103. //            case CARD_SUIT_CLUBS:
  104. //                notation = "c";         //  ASCII: ALT + 5
  105. //                break;
  106. //            default:
  107. //                notation = "";
  108. //        }
  109.         switch (type)
  110.         {
  111.             case CARD_TYPE_ACE:
  112.                 notation += "A";
  113.                 break;
  114.             case CARD_TYPE_TWO:
  115.                 notation += "2";
  116.                 break;
  117.             case CARD_TYPE_THREE:
  118.                 notation += "3";
  119.                 break;
  120.             case CARD_TYPE_FOUR:
  121.                 notation += "4";
  122.                 break;
  123.             case CARD_TYPE_FIVE:
  124.                 notation += "5";
  125.                 break;
  126.             case CARD_TYPE_SIX:
  127.                 notation += "6";
  128.                 break;
  129.             case CARD_TYPE_SEVEN:
  130.                 notation += "7";
  131.                 break;
  132.             case CARD_TYPE_EIGHT:
  133.                 notation += "8";
  134.                 break;
  135.             case CARD_TYPE_NINE:
  136.                 notation += "9";
  137.                 break;
  138.             case CARD_TYPE_TEN:
  139.                 notation += "10";
  140.                 break;
  141.             case CARD_TYPE_JACK:
  142.                 notation += "J";
  143.                 break;
  144.             case CARD_TYPE_QUEEN:
  145.                 notation += "Q";
  146.                 break;
  147.             case CARD_TYPE_KING:
  148.                 notation += "K";
  149.                 break;
  150.             default:
  151.                 notation += "-";
  152.         }
  153.         return notation;
  154.     }
  155. };
Add Comment
Please, Sign In to add comment