-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArcher.cpp
121 lines (105 loc) · 2.62 KB
/
Archer.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
#include <iostream>
#include <string>
#include "Archer.h"
#include "Arrow.h"
Archer::Archer() : Character() {
this->energy = 100;
this->currentArrow = nullptr;
this->count = 0;
for (int i = 0; i < numArrows; i++) {
arrows[i] = nullptr;
}
}
Archer::Archer(string name, string race, int level, int health) : Character(name, race, level, health) {
this -> energy = 100 + level;
this->count = 0;
this->currentArrow = nullptr;
for (int i = 0; i < numArrows; i++) {
arrows[i] = nullptr;
}
}
bool Archer::addArrowType(Arrow* newarrow) {
if (count >= numArrows) {
return false;
}
int pos = 0;
for (int i = 0; i < numArrows; i++) {
if (arrows[i] == nullptr) {
pos = i;
break;
}
}
this->arrows[pos] = newarrow;
this->count++;
return true;
}
Archer::~Archer() {
cout << "Archer arrow types is removed." << endl;
for (int i = 0; i < numArrows; i++) {
if (arrows[i] != nullptr) {
delete arrows[i];
arrows[i] = nullptr;
}
}
this->count = 0;
}
bool Archer::removeArrowType(string& removeArrow) {
int pos = 0;
for (int i = 0; i < numArrows; i++) {
if (arrows[i] != nullptr) {
if (removeArrow == arrows[i]->getName()) {
pos = i;
break;
}
}
}
if (pos == -1) { return false; }
delete arrows[pos];
arrows[pos] = nullptr;
count--;
return true;
}
int Archer::getEnergy() { return energy; }
int Archer::getNumArrows() { return count; }
void Archer::setEnergy(int newenergy) {
this->energy = newenergy;
}
void Archer::EquipWeapon(string& newArrow) {
for (int i = 0; i < numArrows; i++) {
if (arrows[i] != nullptr) {
if (newArrow == arrows[i]->getName()) {
this->currentArrow = arrows[i];
}
}
}
}
void Archer::Attack(Character* target) {
if (energy >= currentArrow->getEnergy()) {
if (currentArrow != nullptr) {
int healthafterdamage = target->getcharacterHealth() - (currentArrow->getDamage() + 0.25 * getcharacterLevel());
target->setcharacterHealth(healthafterdamage);
this->energy -= currentArrow->getEnergy();
}
else {
cout << "No arrow equipped!" << endl;
}
}
else {
cout << "Not enough energy to attack! Rest to restore your energy!" << endl;
}
}
string Archer::getType() {
return "Archer";
}
void Archer::PrintInfo() {
cout << "Archer Information:" << endl;
cout << "Archer Name: " << getcharacterName() << endl;
cout << "Archer Race: " << getcharacterRace() << endl;
cout << "Archer Level: " << getcharacterLevel() << endl;
cout << "Archer Health: " << getcharacterHealth() << endl;
cout << "Archer Energy: " << energy << endl;
cout << "Archer Arrow Type: " << currentArrow->getName() << " Arrow" << endl;
}
void Archer::Rest() {
this->energy += 25;
}