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

8
9
10
11
12
13
14
virginia001 virginia001

2013/12/28

#
nope still the same error...
danpost danpost

2013/12/28

#
Its not the 'import' statement you need. You need to add the instance field:
private String color;
danpost danpost

2013/12/28

#
Its not the 'import' statement you need. You need to add the instance field in the Kratten class:
private String color;
My last post (not the duplicate one) mentioned this.
virginia001 virginia001

2013/12/28

#
at the Kratten class it gives the error at color = c (line 35) ; ...incompatible types
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
public class Kratten extends Actor
{
    private Platform platform;

    public void act()
    {

        if (Greenfoot.mouseClicked(this))  
        {  
            if ( platform.getSchip() != null && platform.getSchip().getKratten()
            == null)
            {  
                platform.getSchip().setKratten(this); // schip laadt krat in
                getWorld().removeObject(this); // 'krat verdwijnt 
            }
        }
    }

    public void setPlatform(Platform p)  
    {  
        platform = p;  
    }  

    public Platform getPlatform()  
    {  
        return platform;  
    }

    private String color;  
    
    public void setColor(Color c)
    {
        color = c ;
    }

    public Color getColor()
    {
        return color;
    }

}
danpost danpost

2013/12/28

#
Change line 33 to:
public void setColor(String c)
and line 38 to:
public String getColor()
and remove line 2.
virginia001 virginia001

2013/12/28

#
okay the error are fixed now. Only problem is when i click on the truck when my ship is docked , it doesn't get the crate though..
danpost danpost

2013/12/28

#
What is the current code of the Vrachtwagen class?
virginia001 virginia001

2013/12/28

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Vrachtwagen here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Vrachtwagen extends Actor
{
    public void act()  
    {  
        if (Greenfoot.mouseClicked(this))  
        {  
            if (platform.getSchip() != null && platform.getSchip().getKratten() != null)  
            {  
                Kratten kratten = platform.getSchip().getKratten();  
                platform.getSchip().setKratten(null);  
                setPlatform(null);  
                // code above should be exact  
                // code below is 'something like' what you need  
                if (!kratten.getColor().equals(this.getColor ())) // bepaal of kleuren gelijk zijn 
                    if (kratten instanceof groen) // checks of kratten object groen is
                        if (platform.getSchip() instanceof Schipgroen) // check of schip groen is 
                        { // lose live  
                            Lives lives = (Lives)getWorld().getObjects(Lives.class).get(0);  
                             
                }  
            }  
        } 

    }
    private Platform platform = null;  

    public void setPlatform(Platform p)  
    {  
        platform = p;  
    }  

    public Platform getPlatform()    
    {    
        return platform;    
    }  
    
    private String color;
    
    public void setColor(String c)
    {
        color = c;
    }

    public String getColor()
    {
        return color;
    }

    

    
}
danpost danpost

2013/12/29

#
Remove lines 23 and 24.
virginia001 virginia001

2013/12/29

#
nope....didn't work
danpost danpost

2013/12/29

#
The only clue you may have at this point is if the 'platform' field for the Vrachtwagen object clicked on becomes null or not. (does it?) BTW, the ship must have a crate to offload onto the truck.
virginia001 virginia001

2013/12/29

#
danpost danpost

2013/12/29

#
And the Vrachtwagen objects do not have 'null' as their 'platform' values?
virginia001 virginia001

2013/12/29

#
it says private Platform platform null when i'm docked with my ship against the platform of the truck
danpost danpost

2013/12/29

#
virginia001 wrote...
it says private Platform platform null when i'm docked with my ship against the platform of the truck
Even before the click?
There are more replies on the next page.
8
9
10
11
12
13
14