Skip to main content
2 of 2
Minor fix to the title.
Vaillancourt
  • 16.4k
  • 17
  • 56
  • 61

How can I define items in my RPG like Java 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 items 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