-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHero.cpp
More file actions
161 lines (148 loc) · 3.74 KB
/
Copy pathHero.cpp
File metadata and controls
161 lines (148 loc) · 3.74 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//
// Created by lapo on 09/06/22.
//
#include "Hero.h"
Hero::Hero(){
torso=new Tool(0);
ring=new Tool(2);
shoes=new Tool(1);
}
bool Hero::IsDead()const {
if(this->getHp()<=0)
return true;
else
return false;
}
void Hero::TakeDamage(int damage) {
this->setHp(Hp-damage);
}
bool Hero::CanAttack()const {
if(this->getStaminaLeft()>0)
return true;
else
return false;
}
int Hero::AttackLight() {
int damage;
damage=(PingHit*Strenght)/2;
this->HasLight=true;
this->damage=damage;
return damage;
}
int Hero::AttackNormal() {
int damage;
damage=(PingHit*Strenght);
this->damage=damage;
return damage;
}
int Hero::AttackStrong() {
int damage;
damage=(PingHit*Strenght)*2;
if(PingHit!=Nping){
damage=0;
}
this->damage=damage;
return damage;
}
void Hero::Regen() {
this->setStaminaLeft(this->getStamina()+this->getStaminaLeft());
if(StaminaLeft>StaminaBar)
StaminaLeft=StaminaBar;
}
void Hero::AttackAnimation() {}
int Hero::Attack() {
int damage;
if(this->Attack1==0)
damage=AttackNormal();
if(this->Attack1==1)
damage=AttackLight();
if(this->Attack1==2)
damage=AttackStrong();
return damage;
}
void Hero::Draw(sf::RenderWindow &finestra)const {
finestra.draw(*this);
}
Hero::~Hero() {
delete torso;
delete ring;
delete shoes;
delete specialTool;
observers.clear();
}
void Hero::Upgrade(Tool* tool) {
int controll=tool->getType();
if(controll==2){
Tool* used=this->getRing();
this->setNping(this->getNping()+((tool->getRarity()-(used->getRarity()))*tool->getBonus()));
}
if(controll==0){
Tool* used=this->getTorso();
this->setMaxHp(this->getMaxHp()+((tool->getRarity()-(used->getRarity()))*tool->getBonus()));
}
if(controll==1){
Tool* used=this->getShoes();
this->setStaminaBar(this->getStaminaBar()+((tool->getRarity()-(used->getRarity()))*2));
this->setStamina(this->getStamina()+((tool->getRarity()-(used->getRarity()))*1));
}
if(controll==3){
SpecialTool* used=this->getSpecialTool();
this->setStrenght(this->getStrenght()+((tool->getRarity()-(used->getRarity()))*tool->getBonus()));
}
}
void Hero::ChangeTool(Tool* tool) {
if (tool->getType() == 0) {
tool->setPosx(1000);
tool->setPosy(300);
tool->setPosition(tool->getPosx(),tool->getPosy());
this->Upgrade(tool);
delete torso;
this->torso=new Tool(*tool);
}
if (tool->getType() == 1) {
tool->setPosx(1300);
tool->setPosy(300);
tool->setPosition(tool->getPosx(),tool->getPosy());
this->Upgrade(tool);
delete this->shoes;
this->shoes=new Tool(*tool);
}
if (tool->getType() == 2) {
tool->setPosx(1000);
tool->setPosy(600);
tool->setPosition(tool->getPosx(),tool->getPosy());
this->Upgrade(tool);
delete this->ring;
this->ring=new Tool(*tool);
}
if (tool->getType() == 3) {
tool->setPosx(1300);
tool->setPosy(600);
tool->setPosition(tool->getPosx(), tool->getPosy());
this->Upgrade(tool);
auto O= this->specialTool->getSpecial();
delete this->specialTool;
this->specialTool = new SpecialTool(*tool,O);
}
}
void Hero::UpgradeStat(int quale) {
if(quale==0){
MaxHp+=15;
}
if(quale==1){
StaminaBar++;
}
if(quale==2){
Nping++;
}
}
void Hero::Subscribe(Observer *o) {
observers.push_back(o);
}
void Hero::Notify() {
for(int i=0;i<observers.size();i++){
if (!observers.empty() && !observers.at(i)->done) {
observers.at(i)->Update();
}
}
}