-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreature.cpp
More file actions
68 lines (51 loc) · 1.6 KB
/
Copy pathCreature.cpp
File metadata and controls
68 lines (51 loc) · 1.6 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
#include "time.h"
#include "Creature.h"
Creature::Creature(CreatureTypes creatureType, const string& name, const string& description) :
creatureType(creatureType),
Entity(Type::CREATURE, name, description) {
this->health = 100;
this->attackPower = 0;
this->armor = 0;
this->baseDamage = 10;
this->level = 1;
}
Creature::~Creature() {
}
int Creature::getHealth() const {
if (this->health <= 0)
return 0;
return this->health;
}
int Creature::getAttackPower() const { return this->attackPower; }
int Creature::getArmor() const { return this->armor; }
int Creature::getDamage() const { return this->baseDamage + (this->attackPower / 10); }
int Creature::getLevel() const { return this->level; }
void Creature::setHealth(int amount) {
this->health = amount;
}
void Creature::setAttackPower(int amount) {
this->attackPower = amount;
}
void Creature::setArmor(int amount) {
this->armor = amount;
}
void Creature::setLevel(int lvl) {
this->level = lvl;
}
const CreatureTypes& Creature::getCreatureType() const { return this->creatureType; }
bool Creature::isAlive() const {
return getHealth() > 0;
// if health is greater than 0 returns true | if less or equal return false
}
int Creature::takeDamage(int amount, int levelDifference) {
// random seed
srand(time(0));
if (levelDifference <= 0)
levelDifference = 1;
// if level difference is negative set to 1
int damageAmount = (amount + (levelDifference * 2)) + (rand() % amount - (armor / 10));
// calculate damage based on level difference and armor
setHealth(getHealth() - damageAmount);
return damageAmount;
// return damage to print the amount
}