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

2025/6/11

Garden Project Help

Philipe_Manor Philipe_Manor

2025/6/11

#
Hello friends, I need help on my Garden project. This is the world class and it keeps saying error. I'm not so sure why...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
public class Garden extends World
{
    public Garden() {   
with a cell size of 1x1 pixels.
        super(800, 600, 1);
        buildWildFlowers(20);
    }
 
    public int getRandomX() {
        return Greenfoot.getRandomNumber(getWidth());
    }
 
    public int getRandomY() {
        return Greenfoot.getRandomNumber(getHeight());
    }
 
    public void buildWildFlowers(int amount) {
        for (int i = 0; i < amount; i++) {
            int flowerType = Greenfoot.getRandomNumber(4); // 0 to 3
            Flower flower = new Flower(flowerType);
 
getRandomX() and getRandomY() from Flower instead of Garden
            int x = flower.getRandomX();
            int y = flower.getRandomY();
 
            addObject(flower, x, y);
        }
    }
}
danpost danpost

2025/6/11

#
Remove line 6. Remove line 24 (or add a double slash to the beginning of the line to comment it out).
You need to login to post a reply.