I want to get the age of the fish2 into the fish1, but fish2.getAge() is always not found. Yet the getAge() in fish2 does return the age of itself, only that fish1 cannot detect getAge().
fish1
fish2
public void eat() { int width = getImage().getWidth(); int height = getImage().getHeight(); Actor fish2 = getOneIntersectingObject(fish2.class); int i = 15; if (fish2 != null) { int j = fish2.getAge(); if (j< i) { World sea = getWorld(); sea.removeObject (fish2); GreenfootImage img = new GreenfootImage("fish2_left_medium.jpg"); direction = 0; img.scale(width+1, height+1); setImage(img); if (i< 77) { i = i+1; }
int age = 0; int r = Greenfoot.getRandomNumber(5)+1; public fish2(int x, int y) { GreenfootImage img = new GreenfootImage("fish3_left_medium.jpg"); img.scale(x, y); setImage(img); getAge(); age = y; } /** * Act - do whatever the fish2 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. int xCoord = getX(); move(-r); getAge(); if (xCoord <=0) { World sea = getWorld(); sea.removeObject (this); } } public int getAge() { return age; }