-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacter.cpp
More file actions
344 lines (301 loc) · 7.88 KB
/
Copy pathCharacter.cpp
File metadata and controls
344 lines (301 loc) · 7.88 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
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/*
Character File
Homework 17 Group Project
Submission 5/24/2017
Team members:
Theo Siswadi
Jia Na (Vera)
Anh Tran (Andrew)
*/
//header files
#include "Character.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
class Character;
//constant arrays for randomize character options
string NAME[] = { "Andrew", "Theo", "Hailey", "Vera" };
string GENDER[] = { "female", "male" };
string RACE[] = { "human", "not human" };
string OCCUPATION[] = { "fighter", "wizard", "cleric" };
string TASKAB[] = { "Cooking", "Cleaning", "Dying" };
string HAIR[] = { "short black", "long white", "short gold" };
string EYECOLOR[] = { "black", "blue", "brown", "green" };
string KINGDOM[] = { "Goat Town", "Sheep Village", "Westeros", "Narnia" };
Character::Character()
{
// Get the system time.
unsigned seed = time(0);
srand(seed);
//customized random number
int randomSelector;
//for all character's characteristics, a random number within a customized range
//is chosen. An element from the respective array will be randomly chosen and set
//to the Character (assigned to Character's respective field)
randomSelector = rand() % (sizeof(NAME) / sizeof(NAME[0]));
setName(NAME[randomSelector]);
randomSelector = rand() % (sizeof(GENDER) / sizeof(GENDER[0]));
setGender(GENDER[randomSelector]);
randomSelector = rand() % (sizeof(RACE) / sizeof(RACE[0]));
setRace(RACE[randomSelector]);
randomSelector = rand() % (sizeof(OCCUPATION) / sizeof(OCCUPATION[0]));
setOccupation(OCCUPATION[randomSelector]);
randomSelector = rand() % (sizeof(TASKAB) / sizeof(TASKAB[0]));
setTaSkAb(TASKAB[randomSelector]);
setLevel(rand() % 10);
setHeight((rand() % 200) + 100);
setWeight((rand() % 100) + 50);
randomSelector = rand() % (sizeof(HAIR) / sizeof(HAIR[0]));
setHair(HAIR[randomSelector]);
randomSelector = rand() % (sizeof(EYECOLOR) / sizeof(EYECOLOR[0]));
setEyeColor(EYECOLOR[randomSelector]);
Conquered = new string;
randomSelector = rand() % (sizeof(KINGDOM) / sizeof(KINGDOM[0]));
setKingdomConquered(KINGDOM[randomSelector]);
}
Character::Character(string name, string occupation, string talent, int height,
int weight, int gChoice, int rChoice, int hChoice, int eChoice,
int kChoice)
{
setName(name);
setGender(GENDER[gChoice - 1]);
setRace(RACE[rChoice - 1]);
setOccupation(occupation);
setTaSkAb(talent);
setLevel(0);
setHeight(height);
setWeight(weight);
setHair(HAIR[hChoice - 1]);
setEyeColor(EYECOLOR[eChoice - 1]);
Conquered = new string;
setKingdomConquered(KINGDOM[kChoice - 1]);
}
// copy constructor
Character::Character(const Character &o)
{
setName(o.Name);
setGender(o.Gender);
setRace(o.Race);
setRace(o.Race);
setOccupation(o.Occupation);
setTaSkAb(o.TaSkAb);
setLevel(o.level);
setHeight(o.Height);
setWeight(o.Weight);
setHair(o.Hair);
setEyeColor(o.EyeColor);
Conquered = new string;
setKingdomConquered(*(o.Conquered));
}
/*-----SETTERS-----*/
void Character::setName(string name)
{
Name = name;
}
void Character::setGender(string gender)
{
Gender = gender;
}
void Character::setRace(string race)
{
Race = race;
}
void Character::setOccupation(string occ)
{
Occupation = occ;
}
void Character::setTaSkAb(string taskab)
{
TaSkAb = taskab;
}
void Character::setLevel(int n)
{
level = n;
}
void Character::setHeight(int height)
{
if (height <= 0) throw InvalidHeight(height);
else Height = height;
}
void Character::setWeight(int weight)
{
if (weight <= 0) throw InvalidWeight(weight);
else Weight = weight;
}
void Character::setHair(string hair)
{
Hair = hair;
}
void Character::setEyeColor(string eye)
{
EyeColor = eye;
}
void Character::setKingdomConquered(string king)
{
*Conquered = king;
}
/*-----GETTERS-----*/
string Character::getName() {
return Name;
}
string Character::getGender() {
return Gender;
}
string Character::getRace() {
return Race;
}
string Character::getOccupation()
{
return Occupation;
}
string Character::getTaSkAb()
{
return TaSkAb;
}
int Character::getLevel()
{
return level;
}
int Character::getHeight() {
return Height;
}
int Character::getWeight() {
return Weight;
}
string Character::getHair() {
return Hair;
}
string Character::getEyeColor() {
return EyeColor;
}
string Character::getKingdomConquered()//theo edit
{
return *Conquered;
}
//member function that displays all the Character's characteristics
void Character::displayInfo()
{
if (getName() == "" && getGender() == "")
{
cout << "Character Doesn't Exist." << endl << endl;
}
else
{
cout << "MY NAME IS " << getName() << " ";
shout();
shout2();
cout << "Name: " << getName() << endl
<< "Gender: " << getGender() << endl
<< "Race: " << getRace() << endl
<< "Occupation: " << getOccupation() << endl
<< "Talents, Abiliities, or Skills: " << getTaSkAb() << endl
<< "Level: " << getLevel() << endl
<< "Hair: " << getHair() << endl
<< "Eyes Color: " << getEyeColor() << endl
<< "Weight: " << getWeight() << " kg" << endl
<< "Height: " << getHeight() << " cm" << endl
<< "Kingdom Conquered: " << getKingdomConquered() << endl << endl;
}
}
/*-----Overload Operators-----*/
// set a character equal to another character through memberwise assignment
void Character::operator=(const Character& o)
{
//delete[] Conquered;
setName(o.Name);
setGender(o.Gender);
setRace(o.Race);
setRace(o.Race);
setOccupation(o.Occupation);
setTaSkAb(o.TaSkAb);
setHeight(o.Height);
setWeight(o.Weight);
setHair(o.Hair);
setEyeColor(o.EyeColor);
Conquered = new string;
setKingdomConquered(*(o.Conquered));
}
// add the heights of the characters
Character Character::operator+(const Character& right)
{
Character temp;
temp.Height = Height + right.Height;
return temp;
}
// get the difference in height of the characters
// if it becomes negative then sets the height to 1
Character Character::operator-(const Character& right)
{
Character temp;
temp.Height = Height - right.Height;
if (temp.Height < 0)
{
temp.Height = 1;
}
return temp;
}
// ++ overloader
// increment the character's level by 1
// prefix
Character Character :: operator++() {
level++;
return *this;
}
bool Character::operator!= (const Character& right)
{
if (this->Height != right.Height)
{
return true;
}
if (this->Weight != right.Weight)
{
return true;
}
return false;
}
ostream& operator<< (ostream& strm, Character& obj)
{
if (obj.getName() == "" && obj.getGender() == "")
{
strm << "Character Doesn't Exist." << endl << endl;
}
else
{
strm << "MY NAME IS " << obj.getName() << " ";
obj.shout();
obj.shout2();
strm << "Name: " << obj.getName() << endl
<< "Gender: " << obj.getGender() << endl
<< "Race: " << obj.getRace() << endl
<< "Occupation: " << obj.getOccupation() << endl
<< "Talents, Abilities, or Skills: " << obj.getTaSkAb() << endl
<< "Level: " << obj.getLevel() << endl
<< "Hair: " << obj.getHair() << endl
<< "Eyes Color: " << obj.getEyeColor() << endl
<< "Weight: " << obj.getWeight() << " kg" << endl
<< "Height: " << obj.getWeight() << " cm" << endl
<< "Kingdom Conquered: " << obj.getKingdomConquered() << endl << endl;
}
return strm;
}
// postfix
Character Character :: operator++(int) {
Character temp = *this;
level++;
return temp;
}
void Character::shout()
{
cout << "YOWZEE I'M A CHARACTER" << endl;
}
void Character::cry()
{
cout << "CHARACTERS!" << endl;
}
void Character::shout2()
{
cry();
cout << " WE RULE!" << endl;
}