-
Notifications
You must be signed in to change notification settings - Fork 0
/
items.h
61 lines (44 loc) · 1.32 KB
/
items.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
#ifndef items_h
#define items_h
#include <string>
class SDL_Texture;
/********************************************************************/
class BasicItem {
public:
BasicItem(const std::string& name) : name_(name), texture_(nullptr) {}
BasicItem(const BasicItem& item) : name_(item.name()), texture_(nullptr) {}
~BasicItem() {}
bool operator==(const BasicItem& rhs) const {
return (name_ == rhs.name());
}
const std::string& name() const {
return name_;
}
static BasicItem& null();
SDL_Texture* texture();
protected:
std::string name_;
SDL_Texture* texture_;
};
/********************************************************************/
class CountedItem {
public:
CountedItem();
CountedItem(const BasicItem& item, int count = 0);
~CountedItem();
static int maxCount() { return 99; }
int addItem(int count = 1);
int removeItem(int count = 1);
const BasicItem& item() const { return item_; }
int count() const { return count_; }
bool isNull() const;
SDL_Texture* texture() const {
CountedItem* non_const = const_cast<CountedItem*>(this);
return non_const->item_.texture();
}
protected:
BasicItem item_;
int count_;
};
/********************************************************************/
#endif // items_h