-
Notifications
You must be signed in to change notification settings - Fork 0
/
container.cpp
75 lines (63 loc) · 1.33 KB
/
container.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
//=======================
// container.cpp
//=======================
#include <iostream>
#include <string>
using namespace std;
// default constructor initialise the inventory as empty
#include "container.h"
container::container()
{
set(0, 0,0);
}
// set the item numbers
void container::set(int heal_n, int mw_n,int lu_n)
{
numOfHeal = heal_n;
numOfMW = mw_n;
numOflu= lu_n;
}
// get the number of heal
int container::nOfHeal()
{
return numOfHeal;
}
// get the number of magic water
int container::nOfMW()
{
return numOfMW;
}
int container::nOflu(){
return numOflu;
}
// display the items;
void container::display()
{
cout << "Your bag contains: " << endl;
cout << "Heal(HP+100): " << numOfHeal << endl;
cout << "Magic Water (MP+80): " << numOfMW << endl;
cout << "luck (avoid an attack): " << numOflu << endl;
}
//use heal
bool container::useHeal()
{
numOfHeal--;
return 1; // use heal successfully
}
//use magic water
bool container::useMW()
{
numOfMW--;
return 1; // use magic water successfully
}
bool container::useluck(){
numOflu--;
return 1;
}
container operator+(const container &x, const container &y){
container c;
c.numOfHeal = x.numOfHeal + y.numOfHeal;
c.numOfMW = x.numOfMW + y.numOfMW;
c.numOflu = x.numOflu + y.numOflu;
return c;
}