adding cs142 code
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
#include "fighter.h"
|
||||
|
||||
fighter::fighter(string name, int max_hp, int strength, int speed, int magic) :
|
||||
name(name), max_hp(max_hp), hp(max_hp), strength(strength),
|
||||
speed(speed), magic(magic) {}
|
||||
|
||||
string fighter::getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
int fighter::getMaximumHP() {
|
||||
return max_hp;
|
||||
}
|
||||
|
||||
int fighter::getCurrentHP() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
int fighter::getStrength() {
|
||||
return strength;
|
||||
}
|
||||
|
||||
int fighter::getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
int fighter::getMagic() {
|
||||
return magic;
|
||||
}
|
||||
|
||||
void fighter::regenerate() {
|
||||
int increase = strength / 6;
|
||||
|
||||
if(increase < 0) {
|
||||
increase = 0;
|
||||
}
|
||||
else if(increase == 0) {
|
||||
increase = 1;
|
||||
}
|
||||
|
||||
if(hp + increase <= max_hp) {
|
||||
hp += increase;
|
||||
}
|
||||
else {
|
||||
hp = max_hp;
|
||||
}
|
||||
}
|
||||
|
||||
void fighter::takeDamage(int damage) {
|
||||
int hurt = damage - (speed / 4);
|
||||
if (hurt <= 0) {
|
||||
hurt = 1;
|
||||
}
|
||||
hp -= hurt;
|
||||
}
|
||||
|
||||
bool fighter::isSimplified() {
|
||||
return false;
|
||||
}
|
||||
|
||||
ostream & operator<<(ostream & os, fighter & f) {
|
||||
os << "{\n"
|
||||
<< " \"name\": \"" << f.name << "\",\n"
|
||||
<< " \"type\": \"" << f.get_type() << "\",\n"
|
||||
<< " \"hp\": " << f.hp << ",\n"
|
||||
<< " \"max hp\": " << f.max_hp << ",\n"
|
||||
<< " \"strength\": " << f.strength << ",\n"
|
||||
<< " \"speed\": " << f.speed << ",\n"
|
||||
<< " \"magic\": " << f.magic << ",\n"
|
||||
<< "}";
|
||||
return os;
|
||||
}
|
||||
Reference in New Issue
Block a user