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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#include "darkgdk.h"
#include "Item.h"
#include "WeaponItem.h"
#include "potionItem.h"
#include <vector>
#include <string.h>
#ifndef INV_H
#define INV_H
class Inventory
{
public:
std::vector<Item*> items;
Inventory()
{
inMenu = false;
timer = 0;
s=0;
}
~Inventory()
{
for(unsigned i = 0; i < items.size(); i++)
{
delete items[i];
}
}
void AddItem(std::string name, int amnt, std::string type, int price)
{
if(type.compare("Weapon")==0)
{
Item *ITEM = new WeaponItem(name,type,amnt,price);
items.push_back(ITEM);
}
if(type.compare("Potion")==0)
{
Item *ITEM = new PotionItem(name,type,amnt,price);
items.push_back(ITEM);
}
//and so on for each item
}
int Select(int x, int y, std::string name, int amnt, std::string type, int price, unsigned position )
{
char *cName = &name[0u];
dbText(x,y,cName);
dbSetCursor(x+ 100,y);
dbPrint(amnt*1.0);
char *cType = &type[0u];
dbText(x+150,y,cType);
dbSetCursor(x+ 300,y);
dbPrint(price*1.0);
if(position==s)
{
if(dbReturnKey()==1 ) return 1;
dbInk(dbRGB(0,255,0),dbRGB(0,0,0));
dbText(x,y,cName);
dbSetCursor(x+ 100,y);
dbPrint(amnt*1.0);
dbText(x+150,y,cType);
dbSetCursor(x+ 300,y);
dbPrint(price*1.0);
dbInk(dbRGB(255,255,255),dbRGB(0,0,0));
}
return 0;
}
void Update()
{
if(timer>0) timer--;
if(dbDownKey()==1 && timer == 0 )
{
if(s<items.size())s++;
if(s>=items.size()) s = 0;
timer = 10;
}
if(dbUpKey()==1 && timer == 0 )
{
if(s>=0)s--;
if(s<0) s = items.size();
timer = 10;
}
if(dbKeyState(15)==1 && timer==0 && inMenu == false)
{
inMenu=true;
timer=30;
}
if(dbKeyState(15)==1 && timer==0 && inMenu == true)
{
inMenu=false;
timer=30;
dbCLS();
}
if(inMenu==true)
{
for(unsigned i =0; i < items.size(); i++)
{
items[i]->Update();
}
for(unsigned i =0; i < items.size(); i++)
{
if(Select(10,i*32,items[i]->get_Name(),items[i]->get_Amount(),items[i]->get_Type(),items[i]->get_Price(),i)==1 && timer==0)
{
items[i]->Use();
if(items[i]->get_Amount()==0) items.erase(items.begin()+i);
timer = 80;
dbCLS();
}
}
}
}
protected:
bool inMenu;
int timer;
int s;
};
#endif
|