-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoldier.cpp
124 lines (109 loc) · 2.94 KB
/
Soldier.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
#include "Soldier.h"
#include "Weapon.h"
#include <iostream>
#include <string>
using namespace std;
Soldier::Soldier() : Character() {
this->soldierWeapon = nullptr;;
this -> soldierStamina = 100;
this->count = 0;
for (int i = 0; i < MAX_WEAPONS; i++) {
weapons[i] = nullptr;
}
}
Soldier::Soldier(string name, string race, int level, int health ) : Character(name, race, level, health) {
soldierStamina = 100 + level;
this->soldierWeapon = nullptr;
this->count = 0;
for (int i = 0; i < MAX_WEAPONS; i++) {
weapons[i] = nullptr;
}
}
Soldier::~Soldier() {
cout << "Soldier weapons is removed" << endl;
for (int i = 0; i < MAX_WEAPONS; i++) {
if (weapons[i] != nullptr) {
delete weapons[i];
weapons[i] = nullptr;
}
}
this->count = 0;
}
Weapon& Soldier::getsoldierWeapon() { return *soldierWeapon; }
int Soldier::getSoldierStamina() { return soldierStamina; }
bool Soldier::AddWeapon(Weapon* newWeapon) {
int pos = 0;
if (count >= MAX_WEAPONS) {
return false;
}
for (int i = 0; i < MAX_WEAPONS; i++) {
if (weapons[i] == nullptr) {
pos = i;
break;
}
}
if (pos < 0) { return false; }
weapons[pos] = newWeapon;
count++;
return true;
}
bool Soldier::removeWeapon(string& weaponName) {
int pos = 0;
for (int i = 0; i < MAX_WEAPONS; i++) {
if (weapons[i] != nullptr) {
if (weapons[i]->getweaponName() == weaponName) {
pos = i;
break;
}
}
}
if (pos < 0) { return false; }
delete weapons[pos];
weapons[pos] = nullptr;
count--;
return true;
}
void Soldier::EquipWeapon(string& newWeapon) {
for (int i = 0; i < MAX_WEAPONS; i++) {
if (weapons[i] != nullptr) {
if (weapons[i]->getweaponName() == newWeapon) {
this->soldierWeapon = weapons[i];
}
}
}
}
void Soldier::printWeapon() {
cout << "Weapon Name: " << soldierWeapon->getweaponName() << endl;
cout << "Weapon Damage: " << soldierWeapon->getdamage() << endl;
cout << "Weapon Cost: " << soldierWeapon->getcost() << endl;
}
void Soldier::Attack(Character* target) {
if (soldierStamina >= soldierWeapon->getcost()) {
if (soldierWeapon != nullptr) {
int healthafterdamage = target->getcharacterHealth() - (soldierWeapon->getdamage() + 0.25 * getcharacterLevel());
target->setcharacterHealth(healthafterdamage);
this->soldierStamina -= soldierWeapon->getcost();
}
else {
cout << "No weapon is equipped!" << endl;
}
}
else {
cout << "Not enough stamina to attack! Please rest to restore stamina!" << endl;
}
}
string Soldier::getType() {
return "Soldier";
}
void Soldier::PrintInfo() {
cout << "Soldier Information:" << endl;
cout << "Soldier Name: " << getcharacterName() << endl;
cout << "Soldier Race: " << getcharacterRace() << endl;
cout << "Soldier Level: " << getcharacterLevel() << endl;
cout << "Soldier Health: " << getcharacterHealth() << endl;
cout << "Soldier Stamina: " << soldierStamina << endl;
cout << "Soldier Weapon: " << soldierWeapon->getweaponName() << endl;
}
void Soldier::Rest() {
this->soldierStamina += 25;
}