I am making a simple 2D platform game and I have run into a slight problem with the Spells I want the player and NPCs to use.
I have an abstract class Spell and a set of subclasses extending Spell. These subclasses indicate the element of the spell, so one subclass might be Fire_Spell. I want to be able to receive a Spell and do something like
if(spell.getClass() == Fire_Spell){
doStuff();
}
But I can’t figure out how to identify if spell is a certain subclass since whenever I try to compare the instance of Spell I have (which will never really be a Spell, always one of the subclasses of Spell) I just can’t find a way that doesn’t either end in an error or which gives a faulty answer.
I have tried something like “attack.isAssignableFrom(Fire_Spell)” and “attack.getClass().isAssignableFrom(Fire_Spell)” but those just say that “Fire_Spellcannot be resolved to a variable” so I wonder what I’m doing wrong.