Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualredw0lf

Posted 22 May 2013 - 10:38 AM

What may be helpful here is the composite pattern http://en.wikipedia.org/wiki/Composite_pattern

 

Here you have an abstract class/interface which is the base of everything else, e.g. an item. You can then have base items (leafs) which cannot be deconstructed further e.g. spikes or cores. You then can have some kind Weapons or other stuff, the components. You can also only see these components as groups and can go further down the path and just make ThrowableWeapons and maybe let a shuriken be a ThrowableWeapon.

 

The recipe could be defined by a hashmap or a table in the class saying for building you will need x spikes and so on. When you're building/crafting the stuff, check if the required items are in your inventory ( which may also be a component) if so remove them from there. If you're trying to decompose an item just add new instances of the items in the table to your inventory.


#1redw0lf

Posted 22 May 2013 - 10:37 AM

What may be helpful here is the composite pattern http://en.wikipedia.org/wiki/Composite_pattern

 

Here you have an abstract class/interface which is the base of everything else, e.g. an item. You can then have base items (leafs) which cannot be deconstructed further e.g. spikes or cores. You then can have some kind Weapons or other stuff, the components. You can also only see these components as groups and can go further down the part and just make ThrowableWeapons and maybe let a shuriken be a throwable weapon.

 

The recipe could be defined by a hashmap or a table in the class saying for building you will need x spikes and so on. When you're building/crafting the stuff, check if the required items are in your inventory ( which may also be a component) if so remove them from there. If you're trying to decompose an item just add new instances of the items in the table to your inventory.


PARTNERS