Skip to main content
1 of 2
MESLewis
  • 499
  • 1
  • 5
  • 13

What are different ways to define items in an RPG like game?

I am casually working on an RPG type game in java but I am having trouble figuring out how I can have items that can do many different things without creating a different class for every item.

As an example, how would I create an Axe that could chop trees and attack monsters?

If I extend either the chopping or the weapon class then I can't extend the other class.

If I have chopping and weapon be an interface then I will have a lot of duplicated code when a dagger can also attack monsters and a different axe can cut trees.

I am hoping there is a way to have a single Item class and load the item's and their respective abilities from a file. If that is possible how can it be done? If it isn't then what is the best way to have items in a game?

MESLewis
  • 499
  • 1
  • 5
  • 13