moved shade into a seperate file

This commit is contained in:
2024-07-11 13:06:05 -04:00
parent 3be70e1212
commit c5f8bd7845
3 changed files with 19 additions and 15 deletions

34
src/shade.cc Normal file
View File

@ -0,0 +1,34 @@
#include "shade.h"
#include <algorithm>
#include <math.h>
shade::shade(const position_list &available_positions):
character{race::rshade} {
pos = available_positions[rng.rand_under(available_positions.size())];
gold = 0;
hostile = true;
}
result shade::attack(const direction dir, character_list &chlist) {
position tmp{pos + MOVE[dir]};
for (auto &ch : chlist)
if (tmp == ch.get_position()) {
return ch.get_hit(race, ATK, base_hit_rate);
}
return result::fine;
}
result shade::get_hit(const enum race &race, const int atk,
const float hitrate) {
if (rng.rand_num() <= hitrate * (float)RAND_MAX) // This is a hit!
HP = std::max(HP - calc_dmg(atk, DEF), 0);
if (HP == 0)
return result::died;
return result::hit;
}