-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
73 lines (60 loc) · 1.31 KB
/
Copy pathPlayer.cpp
File metadata and controls
73 lines (60 loc) · 1.31 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
66
67
68
69
70
71
72
73
#include "Player.h"
Player::Player(std::string& name) {
this->namePlayer = name;
}
//care for istreams
Player::Player(istream& is,const CardFactory* _cFactory) {
}
std::string Player::getName()
{
return namePlayer;
}
int Player::getNumCoins()
{
return numcoins;
}
Player& Player::operator+=(int coins)
{
numcoins += coins;
return (Player&)numcoins;
}
int Player::getMaxNumChains() {
return Maxnumberchains;
}
int Player::getNumChains() {
return chains.size();
}
Chain_base& Player::operator[](int i) {
return *chains[i];
}
void Player::buyThirdChain() {
if (chains.size() == 3) {
cout << " reach chains limit";
if (numcoins >= 2) {
Maxnumberchains += 1;
chains[2] = new Chain_base();
numcoins -= 2;
}
else {
throw "not enough of coins";
}
}
}
void Player::printHand(std::ostream& out, bool all) {
if (all) {
out << hand;
}
else {
Card* top = hand->top();
top->print(out);
}
}
ostream& operator<<(ostream& out, Player& player)
{
out << player.getName(); //Prints the name
out << " has: "<< player.getNumCoins() << " coins" << endl; //Prints the coins
out << player.chains[0] << endl; //Prints the first chain
out << player.chains[1] << endl; //Prints the second chain
out << player.chains[2] << endl; //Prints the third chain (or empty if there isn't one)
return out;
}