-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.cc
141 lines (118 loc) · 3.09 KB
/
Player.cc
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "Player.h"
#include "Building.h"
#include "Property.h"
#include "NonProperty.h"
#include <stdexcept>
Player::Player(std::string name, std::string symbol, int position, std::shared_ptr<Dice> dice,
int TimCup, int money, int TimRound) : name{name}, symbol{symbol}, position{position}, money{money}, rimCup{TimCup}, TimRound{TimRound}, dice{dice} {
// sets initial count to 0
properties["Arts1"] = 0;
properties["Arts2"] = 0;
properties["Eng"] = 0;
properties["Health"] = 0;
properties["Env"] = 0;
properties["Sci1"] = 0;
properties["Sci2"] = 0;
properties["Math"] = 0;
properties["Residence"] = 0;
properties["Gym"] = 0;
}
std::string Player::getName() {
return name;
}
std::string Player::getSymbol() {
return symbol;
}
int Player::getMoney() {
return money;
}
void Player::giveMoney(std::shared_ptr<Player> other, int amount) {
// checks if money is enough
std::string receiver;
if (other == nullptr) {
receiver = "Bank";
} else {
receiver = other->getName();
}
if (money < amount) {
throw NoEnoughMoney("Not enough money!", amount - money, name, receiver);
}
money -= amount;
std::string otherName;
if (other != nullptr) {
other->addMoney(amount);
otherName = other->getName();
} else {
otherName = "Bank";
}
std::string message = name + " pays $" + std::to_string(amount) + " to " + otherName + ".\n";
throw giveMoneyAlert(message);
}
void Player::addMoney(int amount) {
money += amount;
}
unsigned int Player::getProperties(std::string type) {
return properties[type];
}
void Player::addBuilding(std::string type) {
properties[type]++;
}
void Player::loseBuilding(std::string type) {
properties[type]--;
}
bool Player::hasFullMonopoly(std::string type) {
if (type == "Arts1") {
return properties[type] == 2;
} else if (type == "Arts2") {
return properties[type] == 3;
} else if (type == "Eng") {
return properties[type] == 3;
} else if (type == "Health") {
return properties[type] == 3;
} else if (type == "Env") {
return properties[type] == 3;
} else if (type == "Sci1") {
return properties[type] == 3;
} else if (type == "Sci2") {
return properties[type] == 3;
} else if (type == "Math") {
return properties[type] == 2;
} else if (type == "Residence") {
return properties[type] == 4;
} else {
return properties[type] == 2;
}
}
int Player::getPosition() {
return position;
}
void Player::move(int p) {
position = (position + p + 40) % 40;
}
void Player::visit(Building & b) {
b.accept(*this);
}
int Player::getCup() {
return rimCup;
}
void Player::addCup() {
rimCup++;
}
void Player::removeCup() {
if (rimCup == 0) {
throw NoEnoughCup("Not enough Rim Cup!");
}
rimCup--;
}
int Player::getTimRound() {
return TimRound;
}
void Player::stayInLine() {
TimRound++;
}
void Player::leaveLine() {
TimRound = 0;
}
int Player::roll() {
return dice->roll();
}