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

2013/12/17

how to let my ship get a crate

1
2
3
4
5
virginia001 virginia001

2013/12/18

#
I still get the the same error at setKratten even though i've changed the methods like you wanted...
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Kratten here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Kratten extends Actor
{
    /**
     * Act - do whatever the Kratten wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()  
    {
    if (Greenfoot.mouseClicked(this))  
     {  
    if (platform != null && platform.getSchip() != null)  
       {  
        platform.getSchip().setKratten(this); // schip laadt krat in
        getWorld().removeObject(this); // 'krat verdwijnt 
       }  
     }
    }
    private Kratten kratten = null;  
   
   
    
   public Kratten getKratten()  
    {  
        return kratten;  
    }  
    
   private Platform platform = null;  
// with 'get' and 'set' methods for that field  
   private void setPlatform(Platform p)  
   {  
    platform = p;  
   }  
   public Platform getPlatform()  
   {  
    return platform;  
   }  
}    
danpost danpost

2013/12/18

#
Remove lines 26 through 33 from the code above (they do not belong in this class). Need to see the code of the Schip class.
virginia001 virginia001

2013/12/18

#
this the Kratten class with the 26 through 33 removed.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Kratten here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Kratten extends Actor
{
    /**
     * Act - do whatever the Kratten wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()  
    {
     if (Greenfoot.isKeyDown("k"))  
     {  
    //if (platform != null && platform.getSchip() != null) 
     if ( platform.getSchip() != null) 
       {  
        System.out.println("geraakt");   
        platform.getSchip().setKratten(this); // schip laadt krat in
        getWorld().removeObject(this); // 'krat verdwijnt 
       }
    
   
   
    
   public Kratten getKratten()  
    {  
        return kratten;  
    }  
    
   private Platform platform = null;  
// with 'get' and 'set' methods for that field  
   private void setPlatform(Platform p)  
   {  
    platform = p;  
   }  
   public Platform getPlatform()  
   {  
    return platform;  
   }  
}    
virginia001 virginia001

2013/12/18

#
and this is my Schip class. The above with the Kratten class give the error illegal start of expression at public Kratten
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Schip here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Schip extends Actor
{
    /**
     * Act - do whatever the Schip wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    private int speed = 3;
    
    public void act() 
    {
        if(Greenfoot.isKeyDown("left"))
        {
            moveLeft();
        } 
        
        if(Greenfoot.isKeyDown("right"))
        {
            moveRight();
        }
            
        if(Greenfoot.isKeyDown("up"))
        {
            moveUp();
        } 
        
        if(Greenfoot.isKeyDown("down"))
        {
            moveDown();
        } 
    } 
    
    
    
    public void moveRight()
    {
        setLocation(getX() + speed, getY());
        setRotation(180);
        if (getOneIntersectingObject(Platform.class) != null) moveLeft(); 
    }
    
    public void moveLeft()
    {
        setLocation(getX() - speed, getY());
        setRotation(0);
        if (getOneIntersectingObject(Platform.class) != null) moveRight();
        
    }
    
    public void moveUp()
    {
        setLocation(getX(),  getY() - speed);
        setRotation(90);
        if (getOneIntersectingObject(Platform.class) != null) moveDown();
    }
    
    public void moveDown()
    {
        setLocation(getX(),  getY() + speed);
        setRotation(270);
        if (getOneIntersectingObject(Platform.class) != null) moveUp();
    }
       
    
     public Kratten kratten = null; // with cooresponding 'get' and 'set' methods  
   
   public void setKratten(Kratten k)
    {
        kratten = k;
    }
    
   public Kratten getKratten()  
    {  
        return kratten;  
    }   
}

    
        
danpost danpost

2013/12/18

#
You removed the wrong set of lines. The lines I mentioned refer to those lines in the previous post you made of the Kratten class.
virginia001 virginia001

2013/12/18

#
i now have this i am bit confused....
public void act();  
    
     if (Greenfoot.mouseClicked(this))  
     {  
     //if (platform != null && platform.getSchip() != null) 
     if ( platform.getSchip() != null) 
       {  
        System.out.println("geraakt");   
        platform.getSchip().setKratten(this); // schip laadt krat in
        getWorld().removeObject(this); // 'krat verdwijnt 
       }
     }
    
   private Platform platform = null;  

   private void setPlatform(Platform p)  
   {  
    platform = p;  
   }  
   public Platform getPlatform()  
   {  
    return platform;  
   }  
}    
danpost danpost

2013/12/18

#
Referring to line 6 of your last post, why did you remove the other condition (that the 'platform' field could not be 'null')? (look back to the Kratten class code you posted that the lines where not yet removed from -- line 19).
virginia001 virginia001

2013/12/18

#
because my teacher couldn't see a reason why it was there but imma try it out again....also i the line 30 is still illegal error...
danpost danpost

2013/12/18

#
Well, actually, it does not have to be there. The reason I had it there was to cover any time that the crate was not on the platform and was clicked on; but, evidently, that situation never arises (which I was not clear on). Good programming involves covering all the possibilities and that is what I was trying to accomplish there.
virginia001 virginia001

2013/12/18

#
okay what i have now is this, but that still doesn't solve my problem with the line 29 illegal start of expression problem
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Kratten here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Kratten extends Actor
{
    /**
     * Act - do whatever the Kratten wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
  {
    
    if (Greenfoot.mouseClicked(this))  
    {  
    if (platform != null && platform.getSchip() != null) 
    if ( platform.getSchip() != null) 
       {  
        System.out.println("geraakt");   
        platform.getSchip().setKratten(this); // schip laadt krat in
        getWorld().removeObject(this); // 'krat verdwijnt 
       }
    }
    
    private Platform platform = null;  

    private void setPlatform(Platform p)  
    {  
    platform = p;  
    }  
    public Platform getPlatform()  
    {  
    return platform;  
    }  
  } 
}   
danpost danpost

2013/12/18

#
Remove line 27 from your last code post and then auto-indent the class.
virginia001 virginia001

2013/12/18

#
i removed the curly bracket on line 27 if thats what you meant but still same error
danpost danpost

2013/12/18

#
What exactly is the error (copy/past in entirety)?
virginia001 virginia001

2013/12/18

#
private void setPlatform(Platform p) (red cursor comes here) error: illegal start of expression
danpost danpost

2013/12/18

#
OK, what does the class look like now (show in entirety)?
There are more replies on the next page.
1
2
3
4
5