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
|
#include <iostream>
#include "item.h"
#include "inventory.h"
#include <stdlib.h>
#include <string.h>
#pragma GCC diagnostic ignored "-Wwrite-strings"
#ifdef _WIN32
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif
using namespace std;
void AddItem(Inventory& inv,char* name,double weight)
{
int len = strlen(name)+1;
char* itemName = new char[len];
strncpy(itemName,name,len);
cout << "Adding " << itemName << " with a weight of " << weight << "." << endl;
inv.AddItem(Item(itemName,weight));
delete [] itemName;
}
void RemoveItem(Inventory& inv,char* name)
{
cout << "Removing " << name << "." << endl;
inv.RemoveItem(name);
}
int main(int argc, const char * argv[])
{
std::cout << "start" << endl;
Inventory inv;
// Make sure printing an empty inventory works
inv.PrintInventory();
// Make sure adding the first one works
AddItem(inv,"helmet",5);
inv.PrintInventory();
// Add some more items
AddItem(inv,"braclet of power",1);
AddItem(inv,"red potion",2);
inv.PrintInventory();
// Add some duplicates
AddItem(inv,"braclet of power",1);
inv.PrintInventory();
// Add some heavy stuff
AddItem(inv,"bag of gold coins",50);
AddItem(inv,"bag of gold coins",50);
// Now some removes
RemoveItem(inv,"short sword");
RemoveItem(inv,"helmet");
RemoveItem(inv,"braclet of power");
inv.PrintInventory();
return 0;
}
|