-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
68 lines (53 loc) · 1.48 KB
/
Player.cpp
File metadata and controls
68 lines (53 loc) · 1.48 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 "Player.h"
#include <iostream>
// Constructor
Player::Player(const std::string& name, int health, int damage, int defense, int speed)
: name(name), stats(health, damage, defense, speed) {}
// Getter functions
std::string Player::getName() const {
return name;
}
int Player::getHealth() const {
return stats.getHealth();
}
bool Player::isAlive() const {
return getHealth() > 0; // Returns true if health is above 0
}
int Player::getDamage() const {
return stats.getDamage();
}
int Player::getDefense() const {
return stats.getDefense();
}
int Player::getSpeed() const {
return stats.getSpeed();
}
// Setter functions
void Player::setHealth(int health) {
stats.setHealth(health);
}
void Player::setDamage(int damage) {
stats.setDamage(damage);
}
void Player::setDefense(int defense) {
stats.setDefense(defense);
}
void Player::setSpeed(int speed) {
stats.setSpeed(speed);
}
// Buff-related functions
void Player::applyBuff(const Buff& buff) {
if (buff.getDesc().find("Health") != std::string::npos) {
stats.increaseHealth(buff.getValue());
} else if (buff.getDesc().find("Damage") != std::string::npos) {
stats.increaseDamage(buff.getValue());
} else if (buff.getDesc().find("Defense") != std::string::npos) {
stats.increaseDefense(buff.getValue());
}
}
void Player::increaseDamage(int amount) {
setDamage(getDamage() + amount);
}
void Player::takeDamage(int damage) {
stats.takeDamage(damage);
}