ReactOS 0.4.15-dev-8219-ge8b88cf
CardStack Class Reference

#include <cardstack.h>

Collaboration diagram for CardStack:

Public Member Functions

 CardStack ()
 
void NewDeck ()
 
int NumCards () const
 
void Shuffle ()
 
void Clear ()
 
void Reverse ()
 
void Push (const Card card)
 
void Push (const CardStack &cardstack)
 
Card Pop ()
 
CardStack Pop (int items)
 
Card Top ()
 
CardStack Top (int items)
 
void Print ()
 
Card RemoveCard (size_t index)
 
void InsertCard (size_t index, Card card)
 
Cardoperator[] (size_t index)
 
const Cardoperator[] (size_t index) const
 
CardStackoperator+= (Card card)
 
CardStackoperator+= (CardStack &cs)
 
CardStack operator+ (Card card)
 
CardStack operator+ (CardStack &cs)
 

Private Member Functions

 CardStack (CardStack &copythis, size_t fromindex)
 

Private Attributes

Card cardlist [MAX_CARDSTACK_SIZE]
 
int nNumCards
 

Friends

class CardRegion
 

Detailed Description

Definition at line 6 of file cardstack.h.

Constructor & Destructor Documentation

◆ CardStack() [1/2]

CardStack::CardStack ( )
inline

Definition at line 11 of file cardstack.h.

11: nNumCards(0) { }
int nNumCards
Definition: cardstack.h:48

Referenced by Pop(), and Top().

◆ CardStack() [2/2]

CardStack::CardStack ( CardStack copythis,
size_t  fromindex 
)
private

Definition at line 228 of file cardstack.cpp.

229{
230 nNumCards = copythis.nNumCards - fromindex;
231
232 for(int i = 0; i < nNumCards; i++)
233 cardlist[i] = copythis.cardlist[fromindex + i];
234}
Card cardlist[MAX_CARDSTACK_SIZE]
Definition: cardstack.h:47
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Member Function Documentation

◆ Clear()

void CardStack::Clear ( )

Definition at line 37 of file cardstack.cpp.

38{
39 nNumCards = 0;
40}

Referenced by CardRegion::Clear(), CreateSol(), DeckClickProc(), and NewGame().

◆ InsertCard()

void CardStack::InsertCard ( size_t  index,
Card  card 
)

Definition at line 192 of file cardstack.cpp.

193{
195 return;
196
197 if(index > (size_t)nNumCards)
198 return;
199
200 if((size_t)nNumCards == index)
201 {
202 cardlist[nNumCards] = card;
203 nNumCards++;
204 return;
205 }
206
207 //put index into reverse range..
208 index = nNumCards - index - 1;
209
210 nNumCards++;
211
212 //make room for the card
213 for(size_t i = nNumCards; i > index; i--)
214 {
215 cardlist[i] = cardlist[i - 1];
216 }
217
218 cardlist[index] = card;
219}
#define index(s, c)
Definition: various.h:29
#define MAX_CARDSTACK_SIZE
Definition: cardstack.h:4
GLuint index
Definition: glext.h:6031

◆ NewDeck()

void CardStack::NewDeck ( )

Definition at line 42 of file cardstack.cpp.

43{
44 nNumCards = 52;
45
46 for(int i = 0; i < 52; i++)
47 cardlist[i].nValue = i;
48}

Referenced by CardRegion::NewDeck(), and NewGame().

◆ NumCards()

◆ operator+() [1/2]

CardStack CardStack::operator+ ( Card  card)

Definition at line 112 of file cardstack.cpp.

113{
114 CardStack poo = *this;
115 poo.Push(card);
116 return poo;
117}
void Push(const Card card)
Definition: cardstack.cpp:83

◆ operator+() [2/2]

CardStack CardStack::operator+ ( CardStack cs)

Definition at line 119 of file cardstack.cpp.

120{
121 CardStack poo = *this;
122 poo.Push(cs);
123 return poo;
124}
#define cs
Definition: i386-dis.c:442

◆ operator+=() [1/2]

CardStack & CardStack::operator+= ( Card  card)

Definition at line 100 of file cardstack.cpp.

101{
102 Push(card);
103 return *this;
104}

◆ operator+=() [2/2]

CardStack & CardStack::operator+= ( CardStack cs)

Definition at line 106 of file cardstack.cpp.

107{
108 Push(cs);
109 return *this;
110}

◆ operator[]() [1/2]

Card & CardStack::operator[] ( size_t  index)

Definition at line 10 of file cardstack.cpp.

11{
12 if(index >= (size_t)nNumCards) index = nNumCards - 1;
13 return cardlist[nNumCards - index - 1];
14}

◆ operator[]() [2/2]

const Card & CardStack::operator[] ( size_t  index) const

Definition at line 16 of file cardstack.cpp.

17{
18 if(index >= (size_t)nNumCards) index = nNumCards - 1;
19 return cardlist[nNumCards - index - 1];
20}

◆ Pop() [1/2]

Card CardStack::Pop ( )

Definition at line 127 of file cardstack.cpp.

128{
129 if(nNumCards > 0)
130 return cardlist[--nNumCards];
131 else
132 return 0;
133}

Referenced by DeckClickProc(), CardRegion::MoveCard(), NewGame(), CardRegion::OnLButtonDown(), PileRemoveProc(), CardRegion::Pop(), and Undo().

◆ Pop() [2/2]

CardStack CardStack::Pop ( int  items)

Definition at line 135 of file cardstack.cpp.

136{
137 if(items <= nNumCards && nNumCards > 0)
138 {
139 CardStack cs(*this, nNumCards - items);
140
141 nNumCards -= items;
142
143 return cs;
144 }
145 else
146 {
147 return CardStack();
148 }
149}
CardStack()
Definition: cardstack.h:11
static TCHAR * items[]
Definition: page1.c:45

◆ Print()

void CardStack::Print ( )

Definition at line 222 of file cardstack.cpp.

223{
224// for(int i = 0; i < nNumCards; i++)
225// cout << cardlist[i].HiVal() << " ";
226}

Referenced by DeckClickProc().

◆ Push() [1/2]

void CardStack::Push ( const Card  card)

◆ Push() [2/2]

void CardStack::Push ( const CardStack cardstack)

Definition at line 89 of file cardstack.cpp.

90{
91 if(nNumCards + cardstack.nNumCards < MAX_CARDSTACK_SIZE)
92 {
93 int num = cardstack.NumCards();
94
95 for(int i = 0; i < num; i++)
96 cardlist[nNumCards++] = cardstack.cardlist[i];
97 }
98}
int NumCards() const
Definition: cardstack.h:14
GLuint GLuint num
Definition: glext.h:9618

◆ RemoveCard()

Card CardStack::RemoveCard ( size_t  index)

Definition at line 172 of file cardstack.cpp.

173{
174 if(nNumCards == 0 || index >= (size_t)nNumCards)
175 return 0;
176
177 //put index into reverse range..
178 index = nNumCards - index - 1;
179
181
182 nNumCards--;
183
184 for(size_t i = index; i < (size_t)nNumCards; i++)
185 {
186 cardlist[i] = cardlist[i+1];
187 }
188
189 return temp;
190}
Definition: card.h:28
__kernel_size_t size_t
Definition: linux.h:237
static calc_node_t temp
Definition: rpn_ieee.c:38

Referenced by CardRegion::PlayCard().

◆ Reverse()

void CardStack::Reverse ( )

Definition at line 73 of file cardstack.cpp.

74{
75 for(int i = 0; i < nNumCards / 2; i++)
76 {
78 cardlist[i] = cardlist[nNumCards - i - 1];
79 cardlist[nNumCards - i - 1] = temp;
80 }
81}

Referenced by DeckClickProc(), CardRegion::Reverse(), and Undo().

◆ Shuffle()

void CardStack::Shuffle ( )

Definition at line 50 of file cardstack.cpp.

51{
52 int src, dest;
53 Card temp;
54
55 //shuffle 8 times..
56 for(int i = 0; i < 8; i++)
57 for(dest = nNumCards - 1; dest > 0; dest--)
58 {
59 //want to do this:
60 // bad: src = rand() % (dest + 1)
61 // good: src = rand() / (RAND_MAX / (dest+1) + 1)
62
63 //positions from 0 to dest
64 src = rand() / (RAND_MAX / (dest+1) + 1);
65
66 //swap the cards
67 temp = cardlist[src];
70 }
71}
GLenum src
Definition: glext.h:6340
#define RAND_MAX
Definition: stdlib.h:87
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10
static char * dest
Definition: rtl.c:135

Referenced by NewGame(), and CardRegion::Shuffle().

◆ Top() [1/2]

Card CardStack::Top ( )

Definition at line 151 of file cardstack.cpp.

152{
153 if(nNumCards > 0)
154 return cardlist[nNumCards - 1];
155 else
156 return 0;
157}

Referenced by CardRegion::Top(), and Undo().

◆ Top() [2/2]

CardStack CardStack::Top ( int  items)

Definition at line 159 of file cardstack.cpp.

160{
161 if(items <= nNumCards && nNumCards > 0)
162 {
163 return CardStack (*this, nNumCards - items);
164 }
165 else
166 {
167 return CardStack();
168 }
169
170}

Friends And Related Function Documentation

◆ CardRegion

friend class CardRegion
friend

Definition at line 8 of file cardstack.h.

Member Data Documentation

◆ cardlist

◆ nNumCards

int CardStack::nNumCards
private

The documentation for this class was generated from the following files: