-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFighter.cpp
More file actions
55 lines (46 loc) · 1.44 KB
/
Fighter.cpp
File metadata and controls
55 lines (46 loc) · 1.44 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
//
// Created by Nativ on 18/01/2025.
//
#include "Fighter.h"
#include "Monster.h"
Fighter::~Fighter() = default;
Fighter & Fighter::PlayerAttackedByGoblin(const Monster &other) {
if (this->IsItPossibleUseTheSpecialAttack()) {
this->resetRoundCounter();
return *this;
}
int damage = static_cast<int>(std::round(2 * other.getAttackValue()));
this->currentAmountOfLife -= damage;
if (this->currentAmountOfLife < 0)
this->currentAmountOfLife = 0;
return *this;
}
Fighter & Fighter::PlayerAttackedByDragon(const Monster &other) {
if (this->IsItPossibleUseTheSpecialAttack()) {
this->resetRoundCounter();
return *this;
}
int damage = static_cast<int>(std::round(0.5 * other.getAttackValue()));
this->currentAmountOfLife -= damage;
if (this->currentAmountOfLife < 0)
this->currentAmountOfLife = 0;
return *this;
}
Fighter& Fighter::operator=(const Fighter& other) {
if (this == &other)
return *this;
Player::operator=(other);
return *this;
}
string Fighter::getType() const {
return "fighter";
}
Fighter& Fighter::PlayerAttackMonster(Monster &other) { //fighter attack monster
other.MonsterAttackedByFighter(*this);
return *this;
}
bool Fighter::IsItPossibleUseTheSpecialAttack() const {
if (this->roundCounter == 0 || this->roundCounter == 4)
return true;
return false;
}