This was very difficult for me to word into a question so allow me to explain.
I have an abstract class Entity and subclasses House and Warehouse. Each subclass has the same static variables with different values.
When a button is pressed in my game an Action is created which specifies which Entity subclass gets created and placed in the world. I want to write a generic method to place some Entity to the world using the static variables of which ever subclass it is.
I have a class PlaceEntityAction and when the mouse is clicked the appropriate entity will be placed assuming conditions are correct. How can I pass the Class I want to be placed to this Action so it works with any generic Entity?
Here is some dumbed down code:
if (mousePressed)) { if (some conditions are true) { int ex = x pos int ey = y pos if (world.player.haveFunds(e.COST_ENERGY, e.COST_MONEY, e.COST_RESOURCE)) { if (world.places[ex][ey] == 0) { world.entities.add(e); world.player.addEnergy(-e.COST_ENERGY); } } } } So basically how can I get that e to be whatever subclass I pass to the Action since COST_MONEY, etc is static and should be accessed by the Class and not an object?
I'm really struggling to express what I want. Maybe someone can decipher this or provide some other insight regarding my issue. I can provide any other information necessary if you want.
EDIT:
e is an instance of whichever subclass I previously initialized based on an ID system but I don't like this method.