ReactOS 0.4.15-dev-7788-g1ad9096
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
11enum eSuit { Clubs = 0, Diamonds = 1, Hearts = 2, Spades = 3 };
12enum 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
15inline 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
27class Card
28{
29 friend class CardStack;
30
31public:
32
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
99private:
100
103};
104
105#endif /* _CARD_INCLUDED */
#define index(s, c)
Definition: various.h:29
eValue
Definition: card.h:12
@ Queen
Definition: card.h:13
@ Nine
Definition: card.h:13
@ Three
Definition: card.h:12
@ King
Definition: card.h:13
@ Jack
Definition: card.h:13
@ Ten
Definition: card.h:13
@ Four
Definition: card.h:12
@ Eight
Definition: card.h:13
@ Two
Definition: card.h:12
@ Ace
Definition: card.h:12
@ Six
Definition: card.h:12
@ Seven
Definition: card.h:12
@ Five
Definition: card.h:12
eSuit
Definition: card.h:11
@ Clubs
Definition: card.h:11
@ Hearts
Definition: card.h:11
@ Diamonds
Definition: card.h:11
@ Spades
Definition: card.h:11
int MAKE_CARD(int Value, int Suit)
Definition: card.h:15
Definition: card.h:28
Card(int index)
Definition: card.h:45
int Suit() const
Definition: card.h:54
bool FaceUp() const
Definition: card.h:74
Card()
Definition: card.h:33
bool IsRed() const
Definition: card.h:94
bool fFaceUp
Definition: card.h:102
void SetFaceUp(bool fTrue)
Definition: card.h:84
Card(int value, int suit)
Definition: card.h:39
int LoVal() const
Definition: card.h:59
int Idx() const
Definition: card.h:69
bool IsBlack() const
Definition: card.h:89
bool FaceDown() const
Definition: card.h:79
int nValue
Definition: card.h:101
int HiVal() const
Definition: card.h:64
GLuint index
Definition: glext.h:6031
Definition: pdh_main.c:94
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
#define const
Definition: zconf.h:233