Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualEngineProgrammer

Posted 01 September 2012 - 09:18 AM

Hi Djfix,

You should have some classes with inheritance I suppose?
Class Item   -> Class ItemSword, class ItemRing, class ItemPotion which all use the class Item.

If you have this I should recommend you to make 2 classes, class ItemList, class Inventory.

The ItemList class keeps every item, a dropped item and an item in the inventory. So all your items will be stored in this class using a vector.
The Inventory class only hold what you have picked up. To receive all the picked up items you want to say something like:

m_pInventory = m_pItemList->GetAllStoredItems();

So what this means if each item needs to have a bool which says it is stored or not stored.
Then to receive all the stored items you do something like this:
vector<Items*> ItemList::GetAllStoredItems()
{
	vector<Items*> tempVec;
	for(/* look through the vector */)
	{
		if(m_VecItems.at(i)->IsStored() {
		tempVec.pushback(m_VecItems.at(i));
	}
	}
}

This is how I should do it. Certainly there are better ways but this should do also.

EDIT: Ah you are working in Python? I have no idea how it works so I'm doubting Python uses classes. But you say you can handle each language so I won't edit the code I've written. :D Good luck.

~EngineProgrammer

#1EngineProgrammer

Posted 01 September 2012 - 09:16 AM

Hi Djfix,

You should have some classes with inheritance I suppose?
Class Item   -> Class ItemSword, class ItemRing, class ItemPotion which all use the class Item.

If you have this I should recommend you to make 2 classes, class ItemList, class Inventory.

The ItemList class keeps every item, a dropped item and an item in the inventory. So all your items will be stored in this class using a vector.
The Inventory class only hold what you have picked up. To receive all the picked up items you want to say something like:

m_pInventory = m_pItemList->GetAllStoredItems();

So what this means if each item needs to have a bool which says it is stored or not stored.
Then to receive all the stored items you do something like this:
vector<Items*> ItemList::GetAllStoredItems()
{
	vector<Items*> tempVec;
	for(/* look through the vector */)
	{
		if(m_VecItems.at(i)->IsStored() {
		tempVec.pushback(m_VecItems.at(i));
	}
	}
}

This is how I should do it. Certainly there are better ways but this should do also.

~EngineProgrammer

PARTNERS