OK so…
the attack() method is inside the Monster class
class Attack is an abstract class. It has MANY subclasses( so far about 10, planned to exponentiate ). The idea is, that attacks cause damage( or don’t ), and also have some other effect in the battle such as raising its own attack power or lowering an enemy’s defense power. So, class Attack has an abstract method called runEffect( ), which each subclass is forced to override.
For example,
Monster m = new Monster( );
m.attack( new SwordSlash( ), badGuy );
SwordSlash not only does damage, but with a 50% chance it can also lower the target’s defense. So its runEffect() method runs the math, if the Monster is lucky, he lowers his target’s defense.
public void attack( Attack a, Monster target )
{
if( a == null )
return;
System.out.println( "\n" + this.name + " used " + a.getName( ) + "!" );
int damage = 0;
if( a.getPower( ) != 0 )
damage = calcDamage( a, target );
target.takeDamage( damage );
a.runEffect( target ); //AbstractMethodError
a.decrementUsesLeft( );
this.setAttackChoice( null );
}
I understand the error. SwordSlash is being demoted to just an Attack, and a.runEffect( ) is trying to use the runEffect( ) method in Attack which is abstract, hence the error. The question is what now? I don’t want to write a different attack( ) method for each subclass of Attack.