This site requires JavaScript, please enable it in your browser!
Greenfoot back
kaatja
kaatja wrote ...

2012/12/21

Ich möchte, dass mein Baby.class wächst zu einem Kind.class, weiß aber nicht, wie ich die grow Methode hier anwenden soll..

kaatja kaatja

2012/12/21

#
Ich hab es schon hiermit versucht: if (canSee(Wissenschaftler.class)) { getWorld().addObject(new Kind(), getX(), getY()); getWorld().removeObject(this); } da kommt es aber insofern zu Problemen, dass beim Ablauf des Szenarios in einer Error Meldung gesagt wird, der Actor würde sich nicht in der Welt befinden und 2., dass dann nicht ein Kind entsteht, sondern gleich massig viele.. Ich hoffe ihr könnt mir helfen :)
erdelf erdelf

2012/12/21

#
das muss auch in die baby class, in act
SPower SPower

2012/12/21

#
In English, otherwise most people won't be able to help.
kaatja kaatja

2012/12/21

#
Ja habe ich dort.. aber es geht nicht..
erdelf erdelf

2012/12/21

#
bitte mal die ganze baby class
kaatja kaatja

2012/12/21

#
The baby class is named Maggie import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Maggie here. * * @author (your name) * @version (a version number or a date) */ public class Maggie extends Opfer { private static final double WALKING_SPEED = 5.0; /** * Act - do whatever the Homer wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { { if ( atWorldEdge() ) { turn(5); } if ( Greenfoot.getRandomNumber(100) <10 ) { turn(23); } heal(); move(); if (canSee(Wissenschaftler.class)) { getWorld().addObject(new Lisa(), getX(), getY()); getWorld().removeObject(this); } meetMikrobe(); if(meetMikrobe()) { if (Greenfoot.getRandomNumber(100)<50) { getsick(); } } } } public boolean meetMikrobe() { Actor Mikrobe = getOneObjectAtOffset(0, 0, Mikrobe.class) ; if(Mikrobe != null) { return true; } else { return false; } } public void getsick() { setImage("ORIGINAL MAGGIE KRANK.gif"); } public void heal() { if (canSee(Retter.class)) { setImage("ORIGINAL MAGGIE.gif"); } } }
vonmeth vonmeth

2012/12/21

#
    public void act() 
    {
        
            if ( atWorldEdge() )
            {
                turn(5);
            }
            if ( Greenfoot.getRandomNumber(100) <10 )
            {
                turn(23);
            }
            heal();
            move();
            if (canSee(Wissenschaftler.class))  
            {  
                getWorld().addObject(new Lisa(), getX(), getY());  
                getWorld().removeObject(this);
                return;                       // ADD THIS
            }  
            meetMikrobe();
            if(meetMikrobe())
            {
                if (Greenfoot.getRandomNumber(100)<50)
                {
                    getsick();
                }
            }
        
    } 
OR
    public void act() 
    {
        
            if ( atWorldEdge() )
            {
                turn(5);
            }
            if ( Greenfoot.getRandomNumber(100) <10 )
            {
                turn(23);
            }
            heal();
            move();
            meetMikrobe();
            if(meetMikrobe())
            {
                if (Greenfoot.getRandomNumber(100)<50)
                {
                    getsick();
                }
            }
            
            if (canSee(Wissenschaftler.class))  
            {  
                getWorld().addObject(new Lisa(), getX(), getY());  
                getWorld().removeObject(this);
            }  
    } 
I can't explain it in German, but you are trying to use your Maggie.class position (getOneObjectAtOffset) in meetMikrobe method after you have removeObject Maggie.
kaatja kaatja

2012/12/21

#
THANK YOU SO MUCH !!! It finally worked :)
danpost danpost

2012/12/21

#
public void act() 
{
    if (atWorldEdge()) turn(5);
    if (Greenfoot.getRandomNumber(100) <10) turn(23);
    heal();
    move();
    if (canSee(Wissenschaftler.class))  
    {  
        getWorld().addObject(new Lisa(), getX(), getY());  
        getWorld().removeObject(this);
        return; // add this line
    }  
    meetMikrobe(); // remove this line
    if(meetMikrobe() && Greenfoot.getRandomNumber(100)<50) getsick();
}
I condensed the code so it would not take so many lines (I had to properly indent the code anyway, so I could check the bracketing). You do not have to condense your code, but the addition of the 'return' statement is needed to prevent an IllegalStateException later in the code; and the 'meetMikrobe();' statement does nothing because you are not using what it returns for anything. I do not know if your program will do what you want after those changes. If is still doing the same thing, then the problem might be because of coding in another class. Also, post your issue again explaining what is happening and what you want and also post the pertinent code.
You need to login to post a reply.