-
Notifications
You must be signed in to change notification settings - Fork 1
/
Armor.cpp
105 lines (89 loc) · 2.01 KB
/
Armor.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
#include "Weapon.h"
#include "Armor.h"
#include "Item.h"
#include <string>
#include <ostream>
#include <cstdlib>
#include <iostream>
using namespace std;
//Constructor
Armor::Armor(string sName, int iArmorValue) : Item()
{
m_sSlot = "BODY";
m_sType = "";
m_iArmorValue = iArmorValue;
setName(sName);
}
//Copy constructor
Armor::Armor(const Armor& someArmor) : Item(someArmor)
{
m_sSlot = someArmor.getSlot();
m_sType = someArmor.getType();
m_iArmorValue = someArmor.getArmorValue();
}
//Getters
string Armor::getSlot() const
{
return m_sSlot;
}
string Armor::getType() const
{
return m_sType;
}
int Armor::getArmorValue() const
{
return m_iArmorValue;
}
//Setters
void Armor::setSlot(string sSlot)
{
m_sSlot = sSlot;
}
void Armor::setType(string sType)
{
m_sType = sType;
}
void Armor::setArmorValue(int iArmorValue)
{
m_iArmorValue = iArmorValue;
}
//Other mehtods
void Armor::dumpObject()
{
cout << "OBJECT TYPE: Armor" << endl;
dumpObjectData();
}
void Armor::dumpObjectData()
{
cout << "\t - m_sSlot: " << getSlot() << endl;
cout << "\t - m_sType: " << getType() << endl;
cout << "\t - m_iArmorValue: " << getArmorValue() << endl;
}
void Armor::writeFragment(ostream & output, int iTabs)
{
insertTabs(output, iTabs);
output << "<Armor>" << endl;
writeDataAsFragment(output, iTabs + 1);
insertTabs(output, iTabs);
output << "</Armor>" << endl;
}
void Armor::writeDataAsFragment(ostream & output, int iTabs)
{
Item::writeDataAsFragment(output, iTabs);
insertTabs(output, iTabs);
output << "<slot>" << getSlot() << "</slot>" << endl;
insertTabs(output, iTabs);
output << "<type>" << getType() << "</type>" << endl;
insertTabs(output, iTabs);
output << "<armorValue>" << getArmorValue() << "</armorValue>" << endl;
}
void Armor::setElementData(string sElementName, string sValue)
{
Item::setElementData(sElementName, sValue);
if (sElementName == "slot")
setSlot(sValue);
else if (sElementName == "type")
setType(sValue);
else if (sElementName == "armorValue")
setArmorValue(atoi(sValue.c_str()));
}