Im relatively new to greenfoot but I think i have the basics of it down. It is spring break and I am just doing this for a bit of fun but I cannot seem to be able to call a method from another subclass of my code.
I am having trouble call the wither() method. It is defined it the dude subclass:
I don't know what to do
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class killer here.
*
* @author (your name)
* @version (a version number or a date)
*/
public abstract class Killer extends Actor
{
public abstract void act();
public void kill()
{
Actor test = getOneIntersectingObject(Dude.class); // place the class you want to check for, instead of null write "yourclass.class" without "".
if( test == null){
}else{
test.[u]wither[/u]();
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class dude here.
*
* @author (your name)
* @version (a version number or a date)
*/
public abstract class Dude extends Actor
{
private int lives;
public Dude(){
lives = 3;
}
public abstract void act();
public void regen(int x){
lives += x;
}
public void wither(){
lives --;
}
public int getLives(){
return lives;
}
}

