-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiscardPile.cpp
48 lines (40 loc) · 782 Bytes
/
DiscardPile.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
#include "DiscardPile.h"
DiscardPile::DiscardPile(istream&, const CardFactory*)
{
}
DiscardPile::DiscardPile(const CardFactory*)
{
}
DiscardPile& DiscardPile::operator+=(Card* discarded)
{
cards.push_back(discarded);
}
Card* DiscardPile::PickUp()
{
if (cards.size() <= 0) {
return nullptr;
}
else {
Card* topCard = cards.back();
cards.pop_back();
return topCard;
}
}
Card* DiscardPile::Top()
{
if (cards.size() <= 0) {
return nullptr;
}
else {
Card* topCard = cards.back();
return topCard;
}
}
ostream& operator<<(ostream& out, const DiscardPile& discardpile)
{
for (auto inDiscard : discardpile.cards) {
inDiscard->print(out);
cout << " ";
}
return out;
}