-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ammunition.cpp
81 lines (67 loc) · 1.61 KB
/
Ammunition.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
//Ammunition.cpp: defines functions from Ammunition.h
#include "Weapon.h"
#include "Ammunition.h"
#include <ostream>
#include <iostream>
#include <cstdlib>
using namespace std;
//Constructor
Ammunition::Ammunition() : Item()
{
m_iDamageBonus = 0;
m_sType = "Default Type";
}
//Getters
int Ammunition::getDamageBonus() const
{
return m_iDamageBonus;
}
string Ammunition::getType() const
{
return m_sType;
}
//Setters
void Ammunition::setDamageBonus(int iDamageBonus)
{
m_iDamageBonus = iDamageBonus;
}
void Ammunition::setType(string sType)
{
m_sType = sType;
}
//Other methods
void Ammunition::dumpObject()
{
cout << "OBJECT TYPE: Ammunition" << endl;
dumpObjectData();
}
void Ammunition::dumpObjectData()
{
Item::dumpObjectData();
cout << "\t - m_iDamageBonus: " << getDamageBonus() << endl;
cout << "\t - m_sType: " << getType() << endl;
}
void Ammunition::writeFragment(ostream & output, int iTabs)
{
insertTabs(output, iTabs);
output << "<Ammunition>" << endl;
writeDataAsFragment(output, iTabs + 1);
insertTabs(output, iTabs);
output << "</Ammunition>" << endl;
}
void Ammunition::writeDataAsFragment(ostream & output, int iTabs)
{
Item::writeDataAsFragment(output, iTabs);
insertTabs(output, iTabs);
output << "<damageBonus>" << getDamageBonus() << "</damageBonus>" << endl;
insertTabs(output, iTabs);
output << "<type>" << getType() << "</type>" << endl;
}
void Ammunition::setElementData(string sElementName, string sValue)
{
Item::setElementData(sElementName, sValue);
if (sElementName == "damageBonus")
setDamageBonus(atoi(sValue.c_str()));
else if (sElementName == "type")
setType(sValue);
}