ReactOS  0.4.12-dev-685-gf36cbf7
card.h
Go to the documentation of this file.
1 //
2 // CardLib - Card class
3 //
4 // Freeware
5 // Copyright J Brown 2001
6 //
7 
8 #ifndef _CARD_INCLUDED
9 #define _CARD_INCLUDED
10 
11 enum eSuit { Clubs = 0, Diamonds = 1, Hearts = 2, Spades = 3 };
12 enum eValue { Ace = 1, Two = 2, Three = 3, Four = 4, Five = 5, Six = 6, Seven = 7,
13  Eight = 8, Nine = 9, Ten = 10, Jack = 11, Queen = 12, King = 13 };
14 
15 inline int MAKE_CARD(int Value, int Suit)
16 {
17  if(Value < 1) Value = 1;
18  if(Value == 14) Value = 1;
19  if(Value > 13) Value = 13;
20 
21  if(Suit < 0) Suit = 0;
22  if(Suit > 3) Suit = 3;
23 
24  return ((Value - 1) * 4 + Suit);
25 }
26 
27 class Card
28 {
29  friend class CardStack;
30 
31 public:
32 
33  Card()
34  {
35  nValue = 0; //ace of spades by default
36  fFaceUp = true;
37  }
38 
39  Card(int value, int suit) //specify a face value [1-13] and suit [0-3]
40  {
41  nValue = MAKE_CARD(value, suit);
42  fFaceUp = true;
43  }
44 
45  Card(int index) //specify a 0-51 index
46  {
47  if(index < 0) index = 0;
48  if(index > 51) index = 51;
49 
50  nValue = index;
51  fFaceUp = true;
52  }
53 
54  int Suit() const
55  {
56  return (nValue % 4);
57  }
58 
59  int LoVal() const
60  {
61  return (nValue / 4) + 1;
62  }
63 
64  int HiVal() const
65  {
66  return ((nValue < 4) ? 14 : (nValue / 4) + 1);
67  }
68 
69  int Idx() const //unique value (0-51 etc)
70  {
71  return nValue;
72  }
73 
74  bool FaceUp() const
75  {
76  return fFaceUp;
77  }
78 
79  bool FaceDown() const
80  {
81  return !fFaceUp;
82  }
83 
84  void SetFaceUp(bool fTrue)
85  {
86  fFaceUp = fTrue;
87  }
88 
89  bool IsBlack() const
90  {
91  return Suit() == 0 || Suit() == 3;
92  }
93 
94  bool IsRed() const
95  {
96  return !IsBlack();
97  }
98 
99 private:
100 
101  int nValue;
102  bool fFaceUp;
103 };
104 
105 #endif /* _CARD_INCLUDED */
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
int Suit() const
Definition: card.h:54
bool FaceUp() const
Definition: card.h:74
Definition: card.h:13
bool FaceDown() const
Definition: card.h:79
Card(int index)
Definition: card.h:45
Definition: card.h:12
void SetFaceUp(bool fTrue)
Definition: card.h:84
int nValue
Definition: card.h:101
eSuit
Definition: card.h:11
Definition: card.h:12
Definition: card.h:12
Definition: card.h:13
Definition: card.h:13
GLuint index
Definition: glext.h:6031
bool fFaceUp
Definition: card.h:102
Definition: card.h:12
int Idx() const
Definition: card.h:69
int HiVal() const
Definition: card.h:64
bool IsBlack() const
Definition: card.h:89
Definition: card.h:11
Definition: card.h:11
Definition: card.h:13
Definition: card.h:12
bool IsRed() const
Definition: card.h:94
Definition: card.h:13
#define index(s, c)
Definition: various.h:29
Definition: card.h:12
Definition: card.h:27
int LoVal() const
Definition: card.h:59
Card()
Definition: card.h:33
eValue
Definition: card.h:12
Definition: card.h:12
#define const
Definition: zconf.h:230
Definition: card.h:13
Definition: card.h:11
int MAKE_CARD(int Value, int Suit)
Definition: card.h:15
Card(int value, int suit)
Definition: card.h:39
Definition: card.h:11