-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventory.cpp
More file actions
78 lines (64 loc) · 1.79 KB
/
inventory.cpp
File metadata and controls
78 lines (64 loc) · 1.79 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
76
77
78
#include "inventory.h"
Inventory::Inventory(){
//Instantiate itemList? happens automatically
//because it is not a reference
}
Inventory::~Inventory(){};
// Renamed to display because "Inventory" is implied
void Inventory::display() {
wclear(Display::gear_win);
// get the screen size
//int maxItems, mapw; // height of the window is the max number of items we can display, seems to always be 13?
//getmaxyx(Display::gear_win, maxItems, mapw);
//Display bag header
wprintw(Display::gear_win, "BAG [");
//Display capacity in top line, ' ' is free slot, '=' is filled slot
for (unsigned int it = 0; it != maxItems-1; it++) {
if (it < itemList.size()) {
wprintw(Display::gear_win, "=");
}
else {
wprintw(Display::gear_win, " ");
}
}
wprintw(Display::gear_win, "] %d / %d -- %dgp\n", itemList.size(), maxItems, gold);
//Display bag contents
for (auto it = itemList.begin(); it != itemList.end();++it)
{
wprintw(Display::gear_win, " -> ");
it->display(); // equiv to (*it).display();
}
wrefresh(Display::gear_win);
}
void Inventory::addItem(Item& item) {
if (itemList.size() < maxItems) {
itemList.push_back(item);
}
}
void Inventory::useItem(Item& item) {
for (auto it = itemList.begin(); it != itemList.end();++it)
{
Item tempItem = *it;
if (item.name == tempItem.name)
{
itemList.erase(it);
}
}
}
void Inventory::buyItem(Item& item) {} //NYI
void Inventory::sellItem(Item& item) {
//This can be used anywhere atm
//Somehow add gold to the player
for (auto it = itemList.begin(); it != itemList.end();++it)
{
Item tempItem = *it;
if (item.name == tempItem.name)
{
gold += item.value;
itemList.erase(it);
}
}
}
void Inventory::addGold(int newGold) {
gold += newGold;
}