This repository was archived by the owner on May 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTable.cpp
More file actions
65 lines (60 loc) · 1.42 KB
/
Table.cpp
File metadata and controls
65 lines (60 loc) · 1.42 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 "Table.h"
/*Constructor*/
Table::Table(istream& in, const CardFactory *set) {
deck = set->getFactory(in)->getDeck();
dPile = new DiscardPile(in, set);
tArea = new TradeArea(in, set);
}
/*Returns true when a player has won*/
bool Table::win(string& w) {
if (w == A->getName() && deck.empty() && A->getNumCoins() > B->getNumCoins()) {
return true;
}
else if (w == B->getName() && deck.empty() && A->getNumCoins() < B->getNumCoins()) {
return true;
}
else {
return false;
}
}
/*Prints the top card*/
void Table::printHand(bool h) {
if (h) {
cout << A->getName() << ": ";
for (Card* card : A->getPlayersHand()->getHand())
cout << card->getName() << " ";
cout << endl;
cout << B->getName() << ": ";
for (Card* card : B->getPlayersHand()->getHand())
cout << card->getName() << " ";
cout << endl;
}
else {
cout << A->getName() << ": " << A->getPlayersHand()->top()->getName() << endl;
cout << B->getName() << ": " << B->getPlayersHand()->top()->getName() << endl;
}
}
/*Destructor*/
Table::~Table() {
delete A;
delete B;
delete dPile;
delete tArea;
}
void print(std::ostream& out, Table& t) {
//Player 1
out << "Player 1: " << t.A->getName();
out << "\n";
t.A->printHand(out,true);
out << "\n";
//Player 2
out << "Player 2: " << t.B->getName();
out << "\n";
t.B->printHand(out, true);
//Discard pile
out << "\n";
t.dPile->print(out);
//Print Trade Area
out << "\n";
print(out, *t.tArea);
}