Search code examples
javaroguelike

A class system for Roguelike


What would be a good way to implement a race system similar to Roguelike in Java.

I have been thinking about making each creature a subclass of it's race but I'm not sure this is a good way to do things.


Solution

  • You certainly don't want a subclass relationship. I would use composition rather than inheritance.

    In particular, I would make a class Race

    public class Race {
    
        public String name;
    
        public Race(String name) {
            this.name = name;
        }
    
    }
    

    and ensure that each creature has a Race field.