school/cs142/lab10/robot.cpp
2016-04-06 20:45:34 -07:00

31 lines
769 B
C++

#include <cmath>
#include "FighterInterface.h"
#include "robot.h"
robot::robot(string name, int max_hp, int strength, int speed, int magic) :
fighter(name, max_hp, strength, speed, magic),
max_energy(2 * magic), cur_energy(2 * magic), extra_damage(0) {}
int robot::getDamage() {
int damage = strength + extra_damage;
extra_damage = 0;
return damage;
}
void robot::reset() {
hp = max_hp;
cur_energy = max_energy;
}
bool robot::useAbility() {
if(cur_energy - ROBOT_ABILITY_COST >= 0) {
double a = cur_energy/double(max_energy);
double b = pow(a, 4.0);
double increase = strength * b;
extra_damage = int(increase);
cur_energy -= ROBOT_ABILITY_COST;
return true;
}
return false;
}