-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBag.cpp
More file actions
75 lines (67 loc) · 1.22 KB
/
Bag.cpp
File metadata and controls
75 lines (67 loc) · 1.22 KB
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
#include "Bag.h"
#include"Item.h"
Bag::Bag()
{
medicine = new Medicine(5);
monsterball = new Monsterball(10);
gold = new Gold(5000);
}
Bag::~Bag()
{
if (medicine != nullptr)
delete medicine;
if (monsterball != nullptr)
delete monsterball;
if (gold != nullptr)
delete gold;
}
void Bag::UseItem(int type, int amount)
{
if (type == I_Medicine) {
medicine->UseItem(amount);
}
else if (type == I_Monsterball) {
monsterball->UseItem(amount);
}
else if (type == I_Gold) {
gold->UseItem(amount);
}
}
void Bag::AddItem(int type, int amount)
{
if (type == I_Medicine) {
medicine->AddItem(amount);
}
else if (type == I_Monsterball) {
monsterball->AddItem(amount);
}
else if (type == I_Gold) {
gold->AddItem(amount);
}
}
int Bag::GetItemCount(int type)
{
if (type == I_Medicine) {
return medicine->count;
}
else if (type == I_Monsterball) {
return monsterball->count;
}
else if (type == I_Gold) {
return gold->count;
}
return -1;
}
bool Bag::IsUseItem(int type, int amount)
{
if (type == I_Medicine) {
return medicine->IsUseItem(amount);
}
else if (type == I_Monsterball) {
return monsterball->IsUseItem(amount);
}
else if (type == I_Gold) {
return gold->IsUseItem(amount);
}
return false;
}