-
Notifications
You must be signed in to change notification settings - Fork 0
/
hero.cpp
143 lines (108 loc) · 3.08 KB
/
hero.cpp
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
# include "hero.h"
HANDLE rConsole = GetStdHandle(STD_OUTPUT_HANDLE);
Hero::Hero(){
mana = getMaxMana();
exp = 0;
}
Hero::Hero(string name, int level) :Warrior(name, level) {
mana = getMaxMana();
exp = 0;
}
void Hero::setMana(double mana){
this->mana = mana;
if(this->mana > getMaxMana())
this->mana = getMaxMana();
if(this->mana <= 0)
this->mana = 0;
}
void Hero::setExp(int exp){
this->exp = exp;
if(exp >= 100)
this->hp = getMaxhp();
level += exp / 100;
this->exp %= 100;
}
int Hero::getWeapons() const{
int weapons = 0;
for(int i = 0; i < backpack.size(); i++)
if(backpack[i]->getDamage() > 0)
weapons ++;
return weapons;
}
int Hero::getExp() const {
return exp;
}
double Hero::getMana() const {
return mana;
}
double Hero::getMaxMana() const {
return level*10 + 25;
}
void Hero::lifeBar(){
cout<<getName()<<" ["<<getLevel()<<"]"<<endl;
cout<<setfill(' ')<<setw(4);
cout<<"HP: "<<getHp()<<endl;
cout<<"Mana: "<<getMana()<<endl;
cout<<"Exp: "<<getExp()<<endl;
for(int i = 0; i < (int)backpack.size(); i++) {
cout<<"["<<i+1<<"] ";
backpack[i]->print();
}
}
void Hero::lifeBar(Coordinates position, bool all_items){
COORD pos;
pos.X = position.x;
pos.Y = position.y;
SetConsoleCursorPosition(rConsole, pos);
cout<<getName()<<" ["<<getLevel()<<"]"<<endl;
cout<<setfill(' ');
pos.Y++;
SetConsoleCursorPosition(rConsole, pos);
cout<<"HP: ";
barizise(getHp(),getMaxhp(),2);
cout<<' '<<setw(4)<<getHp()<<endl;
pos.Y++;
SetConsoleCursorPosition(rConsole, pos);
cout<<"Mana: ";
barizise(getMana(),getMaxMana(),3);
cout<<' '<<setw(4)<<getMana()<<endl;
pos.Y++;
SetConsoleCursorPosition(rConsole, pos);
cout<<"Exp: "<<setw(4)<<getExp()<<endl;
for(int i = 0; i < (int)backpack.size(); i++){
if(((backpack[i]->getDamage() == 0 && backpack[i]->getDefense() == 0) || backpack[i]->getDamage() > 0) || all_items){
pos.Y++;
SetConsoleCursorPosition(rConsole, pos);
cout<<"["<<i+1<<"]";
backpack[i]->print();
}
}
}
bool Hero::hasItem(Item& item) {
if(item.getName() == "Common sword" || item.getName() == "Common shield")
return true;
for(int i = 0; i < backpack.size(); i++) {
if (&item == backpack[i]){
cout<<"Phew, you already have a/n "<<item.getName()<<" What a luck! "<<endl;
return true;
}
}
return false;
}
void Hero::drop(int index){
backpack.erase(backpack.begin() + index);
}
double Hero::weight(){
double backpack_weight = 0;
for(int i = 0; i < backpack.size(); i++){
backpack_weight += backpack[i]->getWeight();
}
return backpack_weight;
}
double Hero::getDefense(){
double defense = 0;
for(int i = 0; i < backpack.size(); i++){
defense += backpack[i]->getDefense();
}
return defense;
}