Repository navigation
Expand file tree
/
Copy pathDeck.cpp
More file actions
66 lines (54 loc) · 1.43 KB
/
Copy pathDeck.cpp
File metadata and controls
66 lines (54 loc) · 1.43 KB
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
#include "Deck.hpp"
#include <algorithm>
#include <ctime>
Deck::Deck(){
mCards.reserve(52);
srand(static_cast<unsigned int>(time(0)));
populate();
shuffle();
}
Deck::~Deck(){}
void Deck::print(){
cout << "\n{";
for(int i = 0; i < mCards.size(); i++){
cout << *mCards[i];
if(i != 0 && ((i + 1) % 13 == 0) && i != mCards.size() - 1){
cout << endl;
}
}
cout << "}\n" << endl;
}
void Deck::populate(){
clear();
for(int s = Card::CLUBS; s <= Card::SPADES; s++){
for(int r = Card::ACE; r <= Card::KING; r++){
addCard(new Card(static_cast<Card::rank>(r), static_cast<Card::suit>(s)));
}
}
//print(); //Print deck to debug
}
void Deck::shuffle(){
random_shuffle(mCards.begin(), mCards.end());
cout << "\tSHUFFLING\n";
}
void Deck::deal(Participant& aParticipant){
if(!mCards.empty()){
aParticipant.addCard(mCards.back());
mCards.pop_back();
//print(); //Print deck to debug
} else{
cout << "\n\tDeck is empty!" << endl;
cout << "\tShuffling new deck..." << endl;
populate();
shuffle();
}
}
void Deck::additionalCard(Participant& aParticipant){
while(!(aParticipant.isBusted()) && aParticipant.isHitting()){
deal(aParticipant);
cout << aParticipant << endl;
if(aParticipant.isBusted()){
aParticipant.bust();
}
}
}