-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.cpp
153 lines (141 loc) · 3 KB
/
Player.cpp
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
142
143
144
145
146
147
148
149
150
151
152
#include "Player.h"
#include <iostream>
#include <string>
// Authors: Sarmad Hashmi (7249729) and Salman Rana (7395721)
// Project Assignment
// Professor: Jochen Lang
// Course: CSI2372
ostream& operator<<(ostream &_os, const Player &_p) {
_os << _p._x << "\t" << _p._y << "\t" << _p._name << "\t" << _p._gold << "\t" << _p._ruby << "\t" << _p._spice << "\t";
_os << _p._fabric << "\t" << _p._jewel << "\t" << _p._food << "\t" << _p._cart << "\t" << _p._currentCartN;
return _os;
}
istream& operator>>(istream &_is, Player&_p) {
_is >> _p._x >> _p._y >> _p._name >> _p._gold >> _p._ruby >> _p._spice >> _p._fabric >> _p._jewel >> _p._food >> _p._cart >> _p._currentCartN;
return _is;
}
bool Player::canAct() const {
return _food > 0;
}
bool Player::pay(Player &player) {
if (_gold > 0) {
player.incrementGold(1);
_gold--;
return true;
}
return false;
}
void Player::eat() {
if (_food > 0) {
_food--;
}
}
void Player::display() {
cout << "\t \t \t \t"<<_name << "'s Turn" << endl;
cout << "Jewels: " << _jewel << "\t" << "Fabric: " << _fabric << endl << "Spices: " << _spice << "\t" << "Gold: " << _gold << endl << "Ruby: " << _ruby << "\t\t" << "Food: " << _food << endl << "Cart Capacity: " << _cart << endl << "Items in Cart: " << _currentCartN << endl;
cout << endl;
}
string Player::getName() const{
return _name;
}
int Player::getFood() {
return _food;
}
bool Player::incrementCart(int x) {
_cart += x;
return true;
}
bool Player::setFood(int x) {
if (x < 0) {
return false;
}
_food = x;
return true;
}
bool Player::incrementGold(int x) {
_gold += x;
return true;
}
void Player::incrementRuby(int x) {
if (_currentCartN+x > _cart) {
_ruby = _ruby + (_cart - _currentCartN);
_currentCartN = _cart;
}
else if(_currentCartN+x < 0) {
_currentCartN = 0;
_ruby = 0;
}
else {
_currentCartN += x;
_ruby += x;
}
}
void Player::incrementSpice(int x) {
if (_currentCartN+x > _cart) {
_spice = _spice + (_cart - _currentCartN);
_currentCartN = _cart;
}
else if(_currentCartN+x < 0) {
_currentCartN = 0;
_spice = 0;
}
else {
_currentCartN += x;
_spice += x;
}
}
void Player::incrementFabric(int x) {
if (_currentCartN+x > _cart) {
_fabric = _fabric + (_cart - _currentCartN);
_currentCartN = _cart;
}
else if(_currentCartN+x < 0) {
_currentCartN = 0;
_fabric = 0;
}
else {
_currentCartN += x;
_fabric += x;
}
}
void Player::incrementJewel(int x) {
if (_currentCartN+x > _cart) {
_jewel = _jewel + (_cart - _currentCartN);
_currentCartN = _cart;
}
else if(_currentCartN+x < 0) {
_currentCartN = 0;
_jewel = 0;
}
else {
_currentCartN += x;
_jewel += x;
}
}
int Player::getGold() {
return _gold;
}
int Player::getRuby() {
return _ruby;
}
int Player::getSpice() {
return _spice;
}
int Player::getFabric() {
return _fabric;
}
int Player::getJewel() {
return _jewel;
}
int Player::getX() const {
return _x;
}
int Player::getY() const {
return _y;
}
void Player::setX(int x) {
_x = x;
}
void Player::setY(int y) {
_y = y;
}