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

2017/1/8

I need help ;-;

CinnamonCedar CinnamonCedar

2017/1/8

#
I don't know what went wrong... It wont compile and I don't know why
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Play here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Play extends World
{
    private static int aliencount=1;
    /**
     * Constructor for objects of class Play.
     * 
     */
    public Play()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 550, 1); 
        
        prepare();
    }
    
    public void act()
    {
        spawn();
    }
    
    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {
        
        Rocket rocket = new Rocket();
        addObject(rocket,130, 286);
        
    }
    
    public void spawn()//spawn for aliens
    {
        if (getObjects(Alien.class).size() < alienCount)
        {
            addObject(new Alien(), (800), Greenfoot.getRandomNumber(550));
        }
    }
}
davmac davmac

2017/1/8

#
There should be an error message which will help to solve the problem. It looks to me like you've mis-spelt a variable; it's declared on line 11 as all lowercase:
    private static int aliencount=1;
Then it is referred to on line 43 with an uppercase 'C':
        if (getObjects(Alien.class).size() < alienCount)
Nosson1459 Nosson1459

2017/1/8

#
On the side bar in Greenfoot the Play subclass of World should have red lines going through it then when you open the editor, line 43 should have squiggly red lines under it (for the reason discussed above), if you hover the mouse over the words in that line of code a black box should appear near the mouse saying something like "cannot find symbol- variable alienCount" meaning that the variable "alienCount" doesn't exist (it means what it says and says what it means so just be reading it you should know where to look for the problem making it much easier for you to figure out then anyone here since there's no red lines on the site).
You need to login to post a reply.