-
Notifications
You must be signed in to change notification settings - Fork 19
/
Cards.cpp
185 lines (152 loc) · 3.2 KB
/
Cards.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "Cards.h"
#include "Hand.h"
#include <QTime>
Cards::Cards()
{
}
Cards::~Cards()
{
}
void Cards::Clear()
{
m_cards.clear();
}
bool Cards::IsEmpty() const
{
return m_cards.isEmpty();
}
void Cards::Add(const Cards& cards)
{
m_cards = m_cards.unite(cards.m_cards);
QSet<Card>::const_iterator it = cards.m_cards.constBegin();
for (; it != cards.m_cards.constEnd(); it++)
{
CardPoint point = it->point;
}
}
void Cards::Add(const Card& card)
{
m_cards.insert(card);
}
void Cards::Add(const QVector<Cards>& cardsArray)
{
for (int i = 0; i < cardsArray.size(); i++)
{
Add(cardsArray[i]);
}
}
Cards& Cards::operator <<(const Cards& cards)
{
Add(cards);
return *this;
}
Cards& Cards::operator <<(const Card& card)
{
Add(card);
return *this;
}
Cards& Cards::operator <<(const QVector<Cards>& cardsArray)
{
Add(cardsArray);
return *this;
}
void Cards::Remove(const Cards& cards)
{
m_cards.subtract(cards.m_cards);
QSet<Card>::const_iterator it = cards.m_cards.constBegin();
for (; it != cards.m_cards.constEnd(); it++)
{
CardPoint point = it->point;
}
}
void Cards::Remove(const Card& card)
{
m_cards.remove(card);
}
void Cards::Remove(const QVector<Cards>& cardsArray)
{
for (int i = 0; i < cardsArray.size(); i++)
{
Remove(cardsArray[i]);
}
}
bool Cards::Contains(const Cards& cards) const
{
return m_cards.contains(cards.m_cards);
}
bool Cards::Contains(const Card& card) const
{
return m_cards.contains(card);
}
Card Cards::TakeRandomCard()
{
QTime time;
time = QTime::currentTime();
qsrand(time.msec() + time.second() * 1000);
int randomIndex = qrand() % m_cards.size();
QSet<Card>::iterator it = m_cards.begin() + randomIndex;
Card takeCard = *it;
m_cards.erase(it);
return takeCard;
}
int Cards::Count()
{
return m_cards.size();
}
int Cards::PointCount(CardPoint point)
{
int count = 0;
for (QSet<Card>::ConstIterator it = m_cards.constBegin(); it != m_cards.constEnd(); it++)
{
if (it->point == point)
{
count++;
}
}
return count;
}
CardPoint Cards::MinPoint()
{
CardPoint min = Card_End;
if (m_cards.isEmpty()) return Card_End;
QSet<Card>::ConstIterator it = m_cards.constBegin();
for (; it != m_cards.constEnd(); it++)
{
if (it->point < min)
{
min = it->point;
}
}
return min;
}
CardPoint Cards::MaxPoint()
{
CardPoint max = Card_Begin;
if (m_cards.isEmpty()) return Card_Begin;
QSet<Card>::ConstIterator it = m_cards.constBegin();
for (; it != m_cards.constEnd(); it++)
{
if (it->point > max)
{
max = it->point;
}
}
return max;
}
CardList Cards::ToCardList(SortType sortType) const
{
CardList cardList;
for (QSet<Card>::const_iterator it = m_cards.constBegin(); it != m_cards.constEnd(); it++)
{
cardList << *it;
}
if (sortType == Asc)
{
qSort(cardList.begin(), cardList.end(), qLess<Card>());
}
else if (sortType == Desc)
{
qSort(cardList.begin(), cardList.end(), qGreater<Card>());
}
return cardList;
}