/
Merchant.h
61 lines (47 loc) · 1.25 KB
/
Merchant.h
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
/**
* Merchant.cpp
* comp345-assignment-03
*
*/
#ifndef MERCHANT_H
#define MERCHANT_H
#include <vector>
#include "Item.h"
#include "Observer.h"
#include "ItemBuilder.h"
using std::vector;
class Merchant {
public:
// iteration over a vector see:
// http://stackoverflow.com/questions/409348/iteration-over-vector-in-c
void putItem(Item* item) {
merchantStach.push_back(item);
}
void putItem(Item* item, int index) {
merchantStach[index] = item;
}
Item* getItem(int index) {
ItemGenerator* ig = new ItemGenerator();
Item* item = merchantStach[index];
merchantStach[index] = ig->getRandomItem();
return item;
}
Item* peek(int index) {
return merchantStach[index];
}
void removeItem(int index) {
merchantStach[index] = NULL;
}
void deleteItem(int index) {
//delete merchantStach[index];
merchantStach[index] = NULL;
}
vector<Item*> getStach() { return merchantStach; }
int size() { return (int)(merchantStach.size()); }
// observer methods
void attachMerchantObserver(Observer* ob) { observer = ob; }
private:
vector<Item*> merchantStach;
Observer* observer;
};
#endif