forked from matkatmusic/PFMCPP_Project7
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacter.cpp
More file actions
129 lines (112 loc) · 3.37 KB
/
Copy pathCharacter.cpp
File metadata and controls
129 lines (112 loc) · 3.37 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
#include "Character.h"
#include <iostream>
#include "DefensiveItem.h"
#include "HelpfulItem.h"
Character::Character(int hp, int armor_, int attackDamage_ ) :
hitPoints(hp),
armor(armor_),
attackDamage(attackDamage_)
{
initialHitPoints.reset( new int(hitPoints) );
initialArmorLevel.reset( new int( armor) );
initialAttackDamage.reset( new int( attackDamage) );
}
void Character::attack( Character& other )
{
if( hitPoints <= 0 )
{
std::cout << getName() << " can't attack. " << getName() << " is dead." << std::endl;
std::cout << "make another party member use an item to revive them" << std::endl << std::endl;
return;
}
isDefending = false;
std::cout << getName() << " has attacked " << other.getName() << std::endl;
if( other.takeDamage(attackDamage) <= 0 )
{
//if you kill other, you get a boost in hit points and armor.
attackInternal(other);
}
}
void Character::defend()
{
std::cout << getName() << " is defending!!" << std::endl;
for( auto& item : defensiveItems )
{
if( auto* defensiveItem = dynamic_cast<DefensiveItem*>(item.get()) )
{
defensiveItem->use(this);
item.reset(); //can only be used once!
break;
}
}
isDefending = true;
}
void Character::help(Character& other)
{
std::cout << getName() << " is going to help " << other.getName() << std::endl;
for( auto& item : helpfulItems )
{
if( auto* helpfulItem = dynamic_cast<HelpfulItem*>(item.get()) )
{
helpfulItem->use(&other);
item.reset(); //can only be used once!
break;
}
}
}
int Character::takeDamage(int damage)
{
std::cout << getName() << " is taking " << damage << " damage!" << std::endl;
if( damage < armor )
{
armor -= damage;
}
else
{
damage -= armor;
armor = 0;
hitPoints -= damage;
if( hitPoints < 0 )
{
std::cout << getName() << " has died in battle!" << std::endl;
hitPoints = 0;
}
}
printStats();
return hitPoints;
}
#include <cassert>
void Character::attackInternal(Character& other)
{
if( other.hitPoints <= 0 )
{
/*
When you defeat another Character:
a) your stats are restored to their initial value if they are lower than it.
b) your stats are boosted 10%
c) the initial value of your stats is updated to reflect this boosted stat for the next time you defeat another character.
ie same thing to all three stats? ie. HitPoints, Armor, and AttackDamage?
*/
//assert(false);
victorRewardStats(*initialHitPoints, hitPoints);
victorRewardStats(*initialArmorLevel, armor);
victorRewardStats(*initialAttackDamage, attackDamage);
std::cout << getName() << " defeated " << other.getName() << " and leveled up!" << std::endl;
}
}
void Character::victorRewardStats(int& initValue, int& currentValue) // this is the stat logic
{
if(currentValue < initValue)
{
currentValue = initValue;
}
currentValue *= 1.1;
initValue = currentValue;
}
void Character::printStats()
{
std::cout << getName() << "'s stats: " << std::endl;
std::cout << getStats();
std::cout << std::endl;
std::cout << std::endl;
}