-
Notifications
You must be signed in to change notification settings - Fork 1
/
Weapon.cpp
139 lines (118 loc) · 2.78 KB
/
Weapon.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
#include "Weapon.h"
#include "Item.h"
#include <string>
#include <ostream>
#include <cstdlib>
#include <iostream>
using namespace std;
//Constructor
Weapon::Weapon(string sName, int iDamage) : Item()
{
setName(sName);
m_iDamage = iDamage;
m_sType = "default type";
m_iAccuracy = 0;
m_lRange = 0;
m_sAmmoType = "defaulty ammo type";
}
Weapon::Weapon(const Weapon& aWeapon) : Item(aWeapon)
{
m_iDamage = aWeapon.getDamage();
m_sType = aWeapon.getType();
m_iAccuracy = aWeapon.getAccuracy();
m_lRange = aWeapon.getRange();
m_sAmmoType = aWeapon.getAmmoType();
}
//Getters
int Weapon::getDamage() const
{
return m_iDamage;
}
string Weapon::getType() const
{
return m_sType;
}
int Weapon::getAccuracy() const
{
return m_iAccuracy;
}
long Weapon::getRange() const
{
return m_lRange;
}
string Weapon::getAmmoType() const
{
return m_sAmmoType;
}
//Setters
void Weapon::setDamage(int iDamage)
{
m_iDamage = iDamage;
}
void Weapon::setType(string sType)
{
m_sType = sType;
}
void Weapon::setAccuracy(int iAccuracy)
{
m_iAccuracy = iAccuracy;
}
void Weapon::setRange(long lRange)
{
m_lRange = lRange;
}
void Weapon::setAmmoType(string sAmmoType)
{
m_sAmmoType = sAmmoType;
}
//Other methods
void Weapon::dumpObject()
{
cout << "OBJECT TYPE: Weapon" << endl;
dumpObjectData();
}
void Weapon::dumpObjectData()
{
Item::dumpObjectData();
cout << "\t - m_iDamage: " << getDamage() << endl;
cout << "\t - m_sType: " << getType() << endl;
cout << "\t - m_iAccuracy: " << getAccuracy() << endl;
cout << "\t - m_lRange: " << getRange() << endl;
cout << "\t - m_sAmmoType: " << getAmmoType() << endl;
}
void Weapon::writeFragment(ostream & output, int iTabs)
{
insertTabs(output, iTabs);
output << "<Weapon>" << endl;
writeDataAsFragment(output, iTabs + 1);
insertTabs(output, iTabs);
output << "</Weapon>" << endl;
}
void Weapon::writeDataAsFragment(ostream & output, int iTabs)
{
Item::writeDataAsFragment(output, iTabs);
insertTabs(output, iTabs);
output << "<damage>" << getDamage() << "</damage>" << endl;
insertTabs(output, iTabs);
output << "<type>" << getType() << "</type>" << endl;
insertTabs(output, iTabs);
output << "<accuracy>" << getAccuracy() << "</accuracy>" << endl;
insertTabs(output, iTabs);
output << "<range>" << getRange() << "</range>" << endl;
insertTabs(output, iTabs);
output << "<ammoType>" << getAmmoType() << "</ammoType>" << endl;
}
void Weapon::setElementData(string sElementName, string sValue)
{
Item::setElementData(sElementName, sValue);
if (sElementName == "damage")
setDamage(atoi(sValue.c_str()));
else if (sElementName == "type")
setType(sValue);
else if (sElementName == "accuracy")
setAccuracy(atoi(sValue.c_str()));
else if (sElementName == "range")
setRange(atoi(sValue.c_str()));
else if (sElementName == "ammoType")
setAmmoType(sValue);
}