-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cpp
240 lines (204 loc) · 4.14 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#include "Player.h"
using namespace std;
Player::Player()
{
name = "";
gender = female;
age = 0;
job = "";
wins = 0;
votes = 0;
technique = 0;
fatigue = 0;
popularity = 0;
candidate = false;
immunity = false;
}
Player::Player(string n, genderOption g, int a)
{
setName(n);
setGender(g);
setAge(a);
setJob("Cook");
setWins(0);
setVotes(1);
setTechnique(20 + (rand() % 60));
setFatigue(rand() % 100);
setPopularity(rand() % 100);
setCandidate(false);
setImmunity(false);
}
Player::~Player()
{
cout << "Player " << name << " is destroyed." << endl;
}
string Player::getName()
{
return name;
}
genderOption Player::getGender()
{
return gender;
}
int Player::getAge()
{
return age;
}
string Player::getJob()
{
return job;
}
int Player::getWins()
{
return wins;
}
int Player::getVotes()
{
return votes;
}
float Player::getTechnique()
{
return technique;
}
float Player::getFatigue()
{
return fatigue;
}
float Player::getPopularity()
{
return popularity;
}
bool Player::getCandidate()
{
return candidate;
}
bool Player::getImmunity()
{
return immunity;
}
void Player::setName(string val)
{
name = val;
}
void Player::setGender(genderOption val)
{
gender = val;
}
void Player::setAge(int val)
{
if (val >= 18)
age = val;
else
cout << "Age must be an integer >= 18." << endl;
}
void Player::setWins(int val)
{
if (val >= 0)
wins = val;
else
cout << "Wins must be a zero or positive number." << endl;
}
void Player::setVotes(int val)
{
if (val >= 0)
votes = val;
else
cout << "Votes must be a zero or positive number." << endl;
}
void Player::setJob(string val)
{
job = val;
}
void Player::setTechnique(float val)
{
if (val >= 0 && val <= 100)
technique = val;
else
cout << "Technique is a percentage, thus it takes values [0, 100]." << endl;
}
void Player::setFatigue(float val)
{
if (val >= 0 && val <= 100)
fatigue = val;
else
cout << "Fatigue is a percentage, thus it takes values [0, 100]." << endl;
}
void Player::setPopularity(float val)
{
if (val >= 0 && val <= 100)
popularity = val;
else
cout << "Popularity is a percentage, thus it takes values [0, 100]." << endl;
}
void Player::setCandidate(bool val)
{
candidate = val;
}
void Player::setImmunity(bool val)
{
immunity = val;
}
void Player::work()
{
float value = 20 + (((float) rand()) / (float) RAND_MAX)*20;
fatigue += value;
technique *= 1.05;
if (fatigue > 100)
fatigue = 100;
if (technique > 100)
technique = 100;
}
void Player::socialize()
{
float value = -10 + (((float) rand()) / (float) RAND_MAX)*20;
popularity += value;
if (popularity < 0)
popularity = 0;
else if (popularity > 100)
popularity = 100;
}
void Player::practice()
{
technique += 5;
if (technique > 100)
technique = 100;
}
void Player::sleep()
{
fatigue *= 0.5;
}
void Player::compete()
{
float value = 10 + (((float) rand()) / (float) RAND_MAX)*10;
fatigue += value;
if (fatigue > 100)
fatigue = 100;
}
void Player::status()
{
cout << "Name: " << name << endl;
cout << "Gender: ";
if (gender == male)
cout << "Male";
else
cout << "Female";
cout << endl;
cout << "Age: " << age << endl;
cout << "Job: " << job << endl;
cout << "Wins: " << wins << endl;
cout << "Votes: " << votes << endl;
cout << "Technique: " << technique << endl;
cout << "Fatigue: " << fatigue << endl;
cout << "Popularity: " << popularity << endl;
cout << "Candidate: ";
if (candidate == 0)
cout << "false\n" ;
else
cout << "true\n";
cout << "Immunity: ";
if (immunity == 0)
cout << "false";
else
cout << "true";
cout << endl << endl;
}