-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChain.h
62 lines (46 loc) · 1.01 KB
/
Chain.h
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
#include <iostream>
#include "CardFactory.h"
#include "Card.h"
#include <vector>
using namespace std;
class Chain_base;
class Chain_base {
public: Chain_base() {};
virtual int sell() const {
return 0;
};
virtual void print(ostream& out) {
out << "Empty Chain";
};
virtual Chain_base& operator+=(Card* card) {
return *this;
};
};
template <class color>
class Chain : public Chain_base {
public: Chain() {};
public: vector<color*> Cards;
Chain<color>& operator+= (Card* card) {
color* cardType;
cardType = dynamic_cast<Card*>(card);
if (cardType == nullptr) {
throw Card::IllegalType();
}
else {
Cards.push_back(card);
}
return *this;
}
int sell() {
int numCards = Cards.size();
color* topCard = Cards.front();
return topCard->getCardsPerCoin(numCards);
}
void print(ostream& out) {
out << Cards.front()->getName() << " " << endl;
for (auto cardPrint : Cards) {
cardPrint->print(out);
out << " ";
}
}
};