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

2012/5/5

Greenfoot is failing to recognise Java.

craigpd craigpd

2012/5/5

#
Ok. So basically my friend is teaching me Java and my school teacher recommended this program to me. So I started making a basic scenario which includes the classic flash game style of dodging meteors while in a spaceship. Sadly it was not so simple, my friend has tried his best to help me with this and claims it is prefect coding and nothing is wrong with it. Here is the code.
public class deltemeteor extends World
{
    public boolean onContactwithSide(int i, int j)
    {
        if (getX() <= 5 || getX() >= getWorld().getWidth() - 5)
        {
             private void removeMeteor(World world, int i, int j, int k)
        }
        else
        {
            return null;
        }        
}
}
I would like you to focus on this line -
private void removeMeteor(World world, int i, int j, int k)
My friend is near fluent in Java and claims this is perfect coding and there is nothing wrong with it, yet while trying to compile the file an error occurs while states "Illegal start of expression". After a few hours of constantly re-writting the code to see if there is any way around this, I came here for help. Do please help me :/
danpost danpost

2012/5/5

#
Line 7 is good code, but mis-placed. It is good as a method declaration statement, but it occurs within the middle of another method. And the method that it appears in should probably be in the code of an Actor class, not the world class. I am also not quite sure if a boolean can be null (it is either true, false, or not initialized; but not null). You probably want a Meteor class with the following two methods
public void act()
{
    if (onContactWithSide()) 
    {
        getWorld().removeObject(this);
        return;
    }
    // whatever else the meteor might do
}

private boolean onContactWithSide()
{
    return (getX() <=  5 || getX() >= getWorld().getWidth() - 5);
}
craigpd craigpd

2012/5/5

#
Ok,thanks for the help, It got be abit further in, maybe my friend will be able to help me the rest of the way.
You need to login to post a reply.