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

10
11
12
13
14
15
16
danpost danpost

2013/12/30

#
First, remove lines 25 through 34 of the Vrachtwagenplek class. Then, remove all the 'act' methods from all subclasses of Vrachtwagen.
danpost danpost

2013/12/30

#
danpost wrote...
First, remove lines 25 through 34 of the Vrachtwagenplek class. Then, remove all the 'act' methods from all subclasses of Vrachtwagen.
Having two fields for Schip schip' with one being '(hidden)' should have been a clue as to what was causing part of the problem. The empty 'act' method in the vrachtwagenplek class was over-riding the 'act' method of its superclass (Platform class) which was causing the other part of the problem.
virginia001 virginia001

2013/12/30

#
Thanks man working now.... Now for the life part when loading a wrong colored crate on the ship and truck i need to take one heart thats in the upper left corner of the class Lives
danpost danpost

2013/12/30

#
What does your Lives class look like?
virginia001 virginia001

2013/12/30

#
still empty....
danpost danpost

2013/12/30

#
Sorry, I had to look back at your code. The code in the Vrachtwagen class in the 'if' block for when the colors do not match needs changed. The code that I gave, the line 'Lives lives = (Lives) getWorld().getObjects(Lives.class).get(0);' was given with the understanding that you had only one Lives object in the world (that was before I looked at that part of your code). Anyway, what you need to do is determine how many Lives objects are in the world and save it in a local int field, remove from the world the last Lives object in the list returned using 'getWorld().getObjects(Lives.class)' and then if the value of the local int field is one, then do what needs to be done when no lives remain.
virginia001 virginia001

2014/1/2

#
so for example i have this in my Lives class:
private int lives = 3; 
And this for Vrachtwagen class:
getWorld().getObjects(Lives.class) 
danpost danpost

2014/1/2

#
I meant a 'local' field, meaning within the method. So, something like this can be called when colors mis-match.
public void removeLive()
{
    int lives = getWorld().getObjects(Lives.class).size();
    getWorld().removeObject(getWorld().getObjects(Lives.class).get(0));
    if (lives == 1) Greenfoot.stop();
}
virginia001 virginia001

2014/1/2

#
I've now something like this in my Vrachtwagen class (don't know if i putted in the good class though) I get an error at the removeObject of the method removeLine()
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);  

                if (!kratten.getColor().equals(this.getColor ())) // bepaal of kleuren gelijk zijn 
                {

                }  
            }
        }
    }
    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;
    }

    public void removeLive()  
    {  
        int lives = getWorld().getObjects(Lives.class).size();  
        getWorld().removeObject(getWorld().getObjects(Lives.class).get(0));  
        if (lives == 1) Greenfoot.stop();  
    }  
}
deathburrito16 deathburrito16

2014/1/3

#
You could clean up your code a bit, because I notice that the only thing you do in method act is to call method disappear. you could put it all in the act method.
danpost danpost

2014/1/3

#
Change line 54 to this:
getWorld().removeObject((Actor)getWorld().getObjects(Lives.class).get(lives-1));
virginia001 virginia001

2014/1/3

#
when i want to load the crate on a truck a terminal window pops up and says there is something wrong with this code:
            if (platform.getSchip() != null && platform.getSchip().getKratten() != null)  
danpost danpost

2014/1/3

#
Change to:
if (platform != null && platform.getSchip() != null && platform.getSchip().getKrattn() != null)
virginia001 virginia001

2014/1/3

#
error is fixed now thanks.... Only problem is when I loading in or out the wrong color the lives still doesn't dissapear though this is what i have in my Vrachtwagen class due to the lives code
public void removeLive()  
    {  
        int lives = getWorld().getObjects(Lives.class).size();  
        getWorld().removeObject((Actor)getWorld().getObjects(Lives.class).get(lives-1));
        if (lives == 1) Greenfoot.stop();  
    }  
and this line only in the Lives class
private int lives = 3; 
Super_Hippo Super_Hippo

2014/1/3

#
Does this "size()" return the number of objects of the class "Lives" in the world? This private integer "lives" in the Lives class is not needed if you count the number of object in the world. If you want to do it with an integer, this integer should be in the world class or in the class which the player controls. At least it should not be private in the Lives class or every Lives class has its own integer.
There are more replies on the next page.
10
11
12
13
14
15
16