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

2017/3/26

Why this doesn't work ?

salvo salvo

2017/3/26

#
public class Fels  extends Actor
{
    /**
     * Konstruktor der Klasse Fels.
     * Schreibe dort alle Befehle hinein, die im Zeitpunkt der
     * Erzeugung eines Felses ausgeführt werden soll.
     */
    public Fels() 
    { 
    }    
    
    /**
     * Act - do whatever the Fels wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        moveRandomly();//bewege dich zufällig in der Mitte des Spielfeldes (an der Stelle Y=50)
       
        if(isTouching())
        {
           removeTouching(ProjektilRot.class); 
           removeTouching(ProjektilGelb.class);
        }
    }
    
    public boolean isTouching()
    {
     {if(isTouching(ProjektilRot.class))
        return true;
     else
        return false;}
     {if(isTouching(ProjektilGelb.class))
        return true;
     else
        return false;}
     
    
    }
     
   
    

    
    public void moveRandomly()// bewegt sich zufällig horizontal 
  
    {
        int zahl = Greenfoot.getRandomNumber(2);// Zufallszahl zwischen 0,1 zwei Zahlen soll ausgegeben werden; fängt von null an zu zählen
        
        if(zahl == 0) // bedeutet Vergleich
        { moveSouth();
        }
        if(zahl == 1) 
        { moveNorth();
        }
    }
    
   public void moveSouth()
    {
        setLocation(getX(),getY()+1); //die y-Koor wird eins größer
    }
   public void moveNorth()
    {
        setLocation(getX(),getY()-1);//die y-Koor wird eins kleiner
    }
}
salvo salvo

2017/3/26

#
so basically I want that my Object "Fels" removes two Objects Object (ProjektilGelb) and (ProjektilRot) if this touches Fels
danpost danpost

2017/3/26

#
Lines 33 through 36 will never get executed. The method is exited from no matter the result of the first test (line 29). Replace lines 29 through 36 with this:
return isTouching(ProjektilRot.class) || isTouching(ProjektilGelb.class);
salvo salvo

2017/3/26

#
thanks !!!!
You need to login to post a reply.