-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeck.cpp
140 lines (121 loc) · 2.5 KB
/
Deck.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
#include "Deck.h"
Deck::Deck(bool doubleDeck, size_t numOfJockers)
{
if (doubleDeck)
{
for (size_t i = Rank::Two; i < (Rank::NumOfRanks - Rank::Two); i++)
{
for (size_t j = Suit::D; j < (Suit::NumOfSuits - Suit::D); j++)
{
Card* a = new Card(Rank(i), Suit(j));
this->aDeck.push_back(*a);
}
}
for (size_t i = Rank::Two; i < (Rank::NumOfRanks - Rank::Two); i++)
{
for (size_t j = Suit::D; j < (Suit::NumOfSuits - Suit::D); j++)
{
Card* a = new Card(Rank(i), Suit(j));
this->aDeck.push_back(*a);
}
}
}
else
{
for (size_t i = Rank::Two; i < (Rank::NumOfRanks - Rank::Two); i++)
{
for (size_t j = Suit::D; j < (Suit::NumOfSuits - Suit::D); j++)
{
Card* a = new Card(Rank(i), Suit(j));
this->aDeck.push_back(*a);
}
}
}
srand(unsigned(time(NULL)));
this->WildJocker = this->aDeck[rand() % (this->aDeck.size())];
if (numOfJockers > 4)
{
numOfJockers = 4;
}
for (size_t i = 0; i < numOfJockers; i++)
{
Card* a = new Card(Rank(0), Suit(0));
this->aDeck.push_back(*a);
}
}
Card Deck::GetWildJocker()
{
return this->WildJocker;
}
void Deck::ShuffleDeck()
{
srand(unsigned(time(NULL)));
random_shuffle(aDeck.begin(), aDeck.end());
}
void Deck::SortDeck()
{
sort(this->aDeck.begin(), this->aDeck.end(), [](const Card& a, const Card& b) { return a < b; });
}
size_t Deck::GetSize()
{
return this->aDeck.size();
}
vector<Card> Deck::GetDeckCopy()
{
return this->aDeck;
}
Card& Deck::GetCard(size_t place)
{
return this->aDeck[place];
}
void Deck::PushFront(Card& card)
{
this->aDeck.insert(this->aDeck.begin(), 0, card);
}
void Deck::PushBack(Card& card)
{
this->aDeck.push_back(card);
}
Card& Deck::PopFront()
{
assert(!(this->aDeck.empty()));
Card& temp = this->aDeck[0];
this->aDeck.erase(this->aDeck.begin());
this->aDeck.shrink_to_fit();
return temp;
}
Card& Deck::PopBack()
{
Card& temp = this->aDeck[this->aDeck.size() - 1];
aDeck.pop_back();
return temp;
}
void Deck::RemoveFromDeck(size_t place)
{
if (place > (this->GetSize() - 1))
{
cout << "Can't remove the card, index out of bounds. Last card will be removed" << endl;
this->aDeck.pop_back();
}
else
{
this->aDeck.erase(aDeck.begin()+place);
}
this->aDeck.shrink_to_fit();
}
void Deck::RemoveCard(Card& card)
{
for (size_t i; i < this->aDeck.size(); i++)
{
if (this->aDeck[i] == card)
{
this->aDeck.erase(this->aDeck.begin()+i);
this->aDeck.shrink_to_fit();
}
}
}
void Deck::operator=(const Deck& b)
{
this->aDeck = b.aDeck;
this->WildJocker = b.WildJocker;
}