added troll class, cleaned up shade, vampire, and goblin classes

This commit is contained in:
Derek Tan
2024-07-14 02:03:20 -04:00
parent b183fcec7f
commit a521c860df
9 changed files with 64 additions and 12 deletions

View File

@ -33,7 +33,9 @@ enum stat_name {HP, ATK, DEF, hostile};
const int RACE_CNT = 5; // TODO: update as you go
enum race {rshade = 0, rvampire, rgoblin, rdrow, rdragon /* TODO: fill out the other races (including enemies) */};
// TODO: Update races as you go
// PC races [x], Enemy races [x], other? [ ]
enum race {rshade = 0, rdrow, rvampire, rtroll, rgoblin, rhuman, rdwarf, relf, rorc, rmerchant, rdragon, rhalfling};
// TODO: fill out the other races (including enemies)
const int MAX_HP[RACE_CNT] = {125, INF, 110, 150, 150};

View File

@ -1,9 +1,7 @@
#include "goblin.h"
#include <algorithm>
#include <math.h>
goblin::goblin(RNG *rng, const position &pos):
character{rng, race::rshade, pos} {
character{rng, race::rgoblin, pos} {
gold = 0;
hostile = true;
}

View File

@ -1,5 +1,6 @@
#ifndef __GOBLIN_H__
#define __GOBLIN_H__
#include "characters.h"
class goblin final: public character {

View File

@ -2,8 +2,9 @@
#define __RACES_H__
#include "shade.h"
#include "goblin.h"
#include "vampire.h"
#include "troll.h"
#include "goblin.h"
#include "dragon.h"
#endif

View File

@ -1,8 +1,5 @@
#include "shade.h"
#include <algorithm>
#include <math.h>
shade::shade(RNG *rng, const position &pos):
character{rng, race::rshade, pos} {
gold = 0;

36
src/troll.cc Normal file
View File

@ -0,0 +1,36 @@
#include "troll.h"
troll::troll(RNG *rng, const position &pos):
character{rng, race::rtroll, pos} {
gold = 0;
hostile = true;
}
result troll::attack(const direction dir, character_list &chlist) {
position tmp{pos + MOVE[dir]};
if (HP + REGAIN_HP > HP_CAP) {
HP = HP_CAP;
} else {
HP += REGAIN_HP;
}
for (auto &ch : chlist)
if (tmp == ch->get_position()) {
auto res = ch->get_hit(race, ATK, base_hit_rate);
return res;
}
return result::fine;
}
result troll::get_hit(const enum race &race, const int atk,
const fraction hitrate) {
if (rng->trial(hitrate))
HP = std::max(HP - calc_dmg(atk, DEF), 0);
if (HP == 0)
return result::died;
return result::hit;
}

18
src/troll.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef __TROLL_H__
#define __TROLL_H__
#include "characters.h"
class troll final: public character {
static const int REGAIN_HP = 5;
static const int HP_CAP = 120;
public:
troll(RNG *rng, const position &pos);
virtual result attack(const direction dir,
character_list &chlist) override;
virtual result get_hit(const enum race &race, const int afk,
const fraction hit_rate) override;
};
#endif

View File

@ -1,9 +1,7 @@
#include "vampire.h"
#include <algorithm>
#include <math.h>
vampire::vampire(RNG *rng, const position &pos):
character{rng, race::rshade, pos} {
character{rng, race::rvampire, pos} {
gold = 0;
hostile = true;
}

View File

@ -1,5 +1,6 @@
#ifndef __VAMPIRE_H__
#define __VAMPIRE_H__
#include "characters.h"
class vampire final: public character {