-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
78 lines (78 loc) · 2.02 KB
/
Player.cpp
File metadata and controls
78 lines (78 loc) · 2.02 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
74
75
76
77
78
#include <iomanip>
#include "Player.h"
int Player::numPlayer = 1;
bool Player::BuyLand(MapUnit &mapunit) {
if (money_ >= mapunit.GetCost()){
mapunit.SetOwner(id_);
money_ -= mapunit.GetCost();
if (mapunit.GetType()=='C'){
++num_collectable_units_;
}
++num_units_;
return true;
} else{
return false;
}
}
bool Player::UpgradeLand(Upgradable &upgradableunit) {
if (money_ >= upgradableunit.GetUpgradeCost()) {
money_ -= upgradableunit.GetUpgradeCost();
upgradableunit.AddLevel();
return true;
} else{
return false;
}
}
bool Player::PayMoney(Player &player, int money) {
if (money_>= money) {
money_ -= money;
player.money_ += money;
return true;
} else{
return false;
}
}
void Player::Bankrupt() {
name_ = "";
num_collectable_units_ = 0;
money_ = -1;
num_units_ = 0;
location_ = 0;
}
void Player::Move(int dice, int mapsize) {
if (movable_)
{
location_ += dice;
location_ = location_ % mapsize;
}
}
void Player::Create(std::string name) {
name_ = name;
id_ = numPlayer;
num_units_ = 0;
num_collectable_units_ = 0;
location_ = 0;
++numPlayer;
}
std::istream& operator>>(std::istream &is, Player& player){
is >> player.name_;
player.location_ = 0;
player.num_units_ = 0;
player.num_collectable_units_ = 0;
player.money_ = player.startmoney;
player.id_ = player.numPlayer;
++player.numPlayer;
return is;
}
std::ostream& operator<<(std::ostream &os, const Player &player){
os << " ["<< player.id_ << "]"<< std::setw(20) << player.name_ << " $" << player.money_ << " with" <<player.num_units_ << " units" << std::endl;
return os;
}
Player& Player::operator=(const Player &player) {
name_ = player.name_;
id_ = player.id_;
num_units_ = player.num_units_;
num_collectable_units_ = player.num_collectable_units_;
money_ = player.money_;
location_ = player.location_;
}