-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cpp
512 lines (455 loc) · 12.8 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
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
//
// Player.cpp
// Character
//
// Created by RX-78 01 on 3/26/13.
// Copyright (c) 2013 lilongyue. All rights reserved.
//
#include "Player.h"
Player::Player(Messenger &msg)
{
_msg = &msg;
_attack = 10 + Rand::randInt (1, 11);
_hitPoints = 10 + Rand::randInt (1, 11);
_maxHitPoints = _hitPoints;
_defense = 10 + Rand::randInt (1, 11);
_mana = 10 + Rand::randInt (1, 11);
_maxMana = _mana;
_weaponDamage = 8;
_magicDamage = 5 ;
_hpPotion = 10;
_manaPotion = 10;
_experience = 0;
_level = 1;
_numHPPotions = 1;
_numManaPotions = 1;
}
Player::fightVictor Player::turn(Monster &monster, attackOption choice)
{
ostringstream oss;
bool isDead = false;
int damage = 0;
switch(choice)
{
//normal attack
case 0:
damage = attack(monster.getDefense() - Rand::randInt (1, 6));
isDead = monster.hit(damage);
if (damage > 0)
oss << "You attack the monster, doing " << damage << " points of damage.";
else
oss << "Your attack missed.";
_msg->newMessage(oss.str());
oss.str("");
break;
//magic attack
case 1:
if(_mana > 0)
{
isDead = monster.hit(_magicDamage);
oss << "You attack with magic, doing " << _magicDamage << " points of damage.";
_msg->newMessage(oss.str());
decrementMana();
oss.str("");
}
else
_msg->newMessage("You have no manna left!");
break;
//drink HP potion
case 2:
drinkHPPotion();
break;
//drink mana potion
case 3:
drinkManaPotion();
break;
}
if(isDead)
{
_msg->newMessage("You have killed the monster.");
return PLAYER;
}
damage = monster.attack(_defense - Rand::randInt (1, 3));
isDead = hit(damage);
if (damage > 0)
oss << "The monster hits you, doing " << damage << " points of damage.";
else
oss << "The monster's attack misses.";
_msg->newMessage(oss.str());
if(isDead)
{
return MONSTER;
}
else
{
return NEITHER;
}
}
bool Player::randomEncounter()//function for randomly generating an enemy encounter
{
int chanceOfEncouter = 65;
bool enemyEncountered = false;
int randomChanceOfEncounter = 0;
randomChanceOfEncounter = (Rand::randInt (1, 101));
//cout << randomChanceOfEncounter << endl;
if(randomChanceOfEncounter > chanceOfEncouter)
enemyEncountered = true;
return enemyEncountered;
}
//void Player::levelingSystem()
// the leveling system for the character
// update 1 -- updated the the attack, defense ,
// and hitpoits to grow each level -- ross
// update 2 -- added final level -- ross
// update 3 -- max HP now chahes to -- ross
// update 4 -- mana levels now
void Player::levelingSystem()
{
ostringstream oss;
if(_experience >= 100 && _level == 1)
{
_level ++;
_maxHitPoints += 10 +Rand::randInt (1, 11);
_hitPoints = _maxHitPoints;
_attack += 3 + Rand::randInt (1, 11);
_defense += 3 + Rand::randInt (1, 11);
_maxMana += 5 + Rand::randInt (1, 11);
_mana = _maxMana;
oss << "You are now level " << _level << ".";
_msg->newMessage(oss.str());
oss.str("");//add after each
oss << "Your hit points are now " << _hitPoints << ", your attack is now " << _attack << ", your dodge is now " << _defense << ".";
_msg->newMessage(oss.str());
oss.str("");
}
if(_experience >= 275 && _level == 2)
{
_level ++;
_maxHitPoints += 10 +Rand::randInt (1, 11);
_hitPoints = _maxHitPoints;
_attack += 5 + Rand::randInt (1, 11);
_defense += 5 + Rand::randInt (1, 11);
_maxMana += 5 + Rand::randInt (1, 11);
_mana = _maxMana;
oss << "You are now level " << _level << ".";
_msg->newMessage(oss.str());
oss.str("");
oss << "Your hit points are now " << _hitPoints << ", your attack is now " << _attack << ", your dodge is now " << _defense << ".";
_msg->newMessage(oss.str());
oss.str("");
}
if(_experience >= 470 && _level == 3)
{
_level ++;
_maxHitPoints += 10 +Rand::randInt (1, 11);
_hitPoints = _maxHitPoints;
_attack += 8 + Rand::randInt (1, 11);
_defense += 8 + Rand::randInt (1, 11);
_maxMana += 5 + Rand::randInt (1, 11);
_mana = _maxMana;
oss << "You are now level " << _level << ".";
_msg->newMessage(oss.str());
oss.str("");
oss << "Your hit points are now " << _hitPoints << ", your attack is now " << _attack << ", your dodge is now " << _defense << ".";
_msg->newMessage(oss.str());
oss.str("");
}
if(_experience >= 680 && _level == 4)
{
_level ++;
_maxHitPoints += 10 +Rand::randInt (1, 11);
_hitPoints = _maxHitPoints;
_attack += 13 + Rand::randInt (1, 11);
_defense += 13 + Rand::randInt (1, 11);
_maxMana += 5 + Rand::randInt (1, 11);
_mana = _maxMana;
oss << "You are now level " << _level << ".";
_msg->newMessage(oss.str());
oss.str("");
oss << "Your hit points are now " << _hitPoints << ", your attack is now " << _attack << ", your dodge is now " << _defense << ".";
_msg->newMessage(oss.str());
oss.str("");
}
// this level means you won
if (_experience >= 1000 && _level == 5)
{
_level ++;
oss << "You are now level " << _level << "You Win.";
_msg->newMessage(oss.str());
oss.str("");
}
}
// void Player::enemyDrop (Monster & monster)
// function for generating what items an enemy drops when killed
// update 1 -- change param from monster to monster reference - ross
// update 2 -- based exp gaind on monster lvl -ross
void Player::enemyDrop (Monster & monster)
{
ostringstream oss;
int tempExp = 10 + Rand::randInt (1, monster.getLevel()*10+1);
_experience += tempExp;
oss << "You got " << tempExp << " experience points.";
_msg->newMessage(oss.str());
oss.str("");
oss << "You have " << _experience << " experience points.";
_msg->newMessage(oss.str());
oss.str("");
levelingSystem();
int baseEnemyDropPercentage = 35;
int randomEnemyDropPercentage = 0;
int numPotions = 0;
int potionDropPercentage = 70;
int randomPotionDropPercentage = 0;
int numCoins = 0;
int coinDropPercentage = 30;
int randomCoinDropPercentage = 0;
randomEnemyDropPercentage = Rand::randInt (1, 101);
//cout << "Random enemy drop percentage is " << randomEnemyDropPercentage << endl;
if(randomEnemyDropPercentage > baseEnemyDropPercentage)
{
randomPotionDropPercentage = Rand::randInt (1, 101);
if(randomPotionDropPercentage > potionDropPercentage)
{
int kindOfPotion;
kindOfPotion = Rand::randInt(1,3);
if(kindOfPotion == 1)
{
oss << "You got an HP potion!";
_msg->newMessage(oss.str());
oss.str("");
addHPPotion(numPotions);
}
else
{
oss << "You got a mana potion!";
_msg->newMessage(oss.str());
oss.str("");
addManaPotion(numPotions);
}
}
randomCoinDropPercentage = Rand::randInt (1, 11);
if(randomCoinDropPercentage > coinDropPercentage)
{
numCoins = Rand::randInt (1, 11);
oss << "You got " << numCoins << " coins.";
_msg->newMessage(oss.str());
oss.str("");
addCoins(numCoins);
}
}
}
// canidate for deletion i don't think we use this
// and it isn't even set up to work with messenger -- ross
void Player::treasureChest()//randomly generates chests for the player to find
{
//cout << "Called the treasure chest function" << endl;
int baseChanceOfChest = 50;
int randomChanceOfChest = Rand::randInt (1, 101);
int numPotions = 0;
int potionDropPercentage = 70;
int randomPotionDropPercentage = 0;
int numCoins = 0;
int coinDropPercentage = 30;
int randomCoinDropPercentage = 0;
if(randomChanceOfChest > baseChanceOfChest)
{
char chestInput;
cout << "You see a chest. Open it? Type 'Y' for yes, or 'N' for no." << endl;
cin >> chestInput;
if(toupper(chestInput) == 'Y')
{
randomPotionDropPercentage = Rand::randInt (1, 101);
if(randomPotionDropPercentage > potionDropPercentage)
{
cout << "You got a potion!" << endl;
numPotions ++;
addHPPotion(numPotions);
}
randomCoinDropPercentage = Rand::randInt (1, 101);
if(randomCoinDropPercentage > coinDropPercentage)
{
numCoins = Rand::randInt (1, 11);
cout << "You got " << numCoins << " coins." << endl;
addCoins(numCoins);
}
else
{
cout << "The chest is empty." << endl;
}
}
if(toupper(chestInput) == 'N')
{
cout << "You decide not to open the chest and move on." << endl;
}
}
}
void Player::movementDescription()//called when the player moves, gives some description of the surroundings to spice things up
{
ostringstream oss;
int randomDescription;
randomDescription = Rand::randInt (1, 11);
switch(randomDescription)
{
case 1:
oss << "Your unease grows with each room.";
_msg->newMessage(oss.str());
oss.str("");
break;
case 2:
oss << "How many rooms could there be?";
_msg->newMessage(oss.str());
oss.str("");
break;
case 3:
oss << "The air is cold and damp, and the floor slick.";
_msg->newMessage(oss.str());
oss.str("");
break;
case 4:
oss << "You smell death.";
_msg->newMessage(oss.str());
oss.str("");
break;
case 5:
oss << "Something crunches under your foot.";
_msg->newMessage(oss.str());
oss.str("");
break;
case 6:
oss << "A scream pierces the dead silence.";;
_msg->newMessage(oss.str());
oss.str("");
break;
case 7:
oss << "Your heart beats furiously in fear.";
_msg->newMessage(oss.str());
oss.str("");
break;
case 8:
oss << "Despite the cold, you're sweating.";
_msg->newMessage(oss.str());
oss.str("");
break;
case 9:
oss << "You wonder if you'll ever get out of here.";
_msg->newMessage(oss.str());
oss.str("");
break;
case 10:
oss << "You hear a faint dripping sound.";
_msg->newMessage(oss.str());
oss.str("");
break;
}
}
void Player::addHPPotion(int numHPPotions)
{
_numHPPotions += 1;
}
void Player::addManaPotion(int numManaPotions)
{
_numManaPotions += 1;
}
void Player::subtractHPPotion()
{
_numHPPotions -= 1;
}
void Player::subtractManaPotions()
{
_numManaPotions -= 1;
}
void Player::addCoins (int numCoins)//increments number of coins
{
_coins += numCoins;
}
void Player::magicAttack()
{
_mana --;
//function that decrements monster hp
}
int Player::getMana()
{
return _mana;
}
void Player::setMana(int mana)
{
_mana = mana;
}
int Player::getMaxMana()
{
return _maxMana;
}
void Player::setMaxMana(int maxMana)
{
_maxMana = maxMana;
}
int Player::getExperience()
{
return _experience;
}
void Player::setExperience(int exp)
{
_experience = exp;
}
int Player::getHPPotions()
{
return _numHPPotions;
}
void Player::setHPPotions(int potions)
{
_numHPPotions = potions;
}
int Player::getManaPotions()
{
return _numManaPotions;
}
void Player::setManaPotions(int potions)
{
_numManaPotions = potions;
}
int Player::getCoins()
{
return _coins;
}
void Player::setCoins(int coins)
{
_coins = coins;
}
void Player::drinkHPPotion()
{
if(_numHPPotions > 0)
{
_hitPoints += _hpPotion;
if(_hitPoints > _maxHitPoints)
{
_hitPoints = _maxHitPoints;
}
subtractHPPotion();
_msg->newMessage("Drinking a health potion makes you feel stronger.");
}
else
_msg->newMessage("You have no health potions!");
}
void Player::drinkManaPotion()
{
if(_numManaPotions > 0)
{
_mana += _manaPotion;
if(_mana > _maxMana)
{
_mana = _maxMana;
}
subtractManaPotions();
_msg->newMessage("Drinking a magic potion revives your energy.");
}
else
_msg->newMessage("You have no magic potion!");
}
void Player::decrementMana()
{
_mana -= 1;
}
int Player::getLevel()
{
return _level;
}