I am new on this platform of creating games, and to java in general. I have worked in C++ for a year at school, and they do look similar, but I have some problems. I do not understand why the following code doesn't want to randomly spawn "worms" at random times across the map. Please help me understand what I have done wrong.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Worm here. * * @author (your name) * @version (a version number or a date) */ public class Worm extends Actor { /** * Act - do whatever the Worm wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { theyHatin(); spawnal(); } public void theyHatin() { if(Greenfoot.getRandomNumber(100)<30) { move(Greenfoot.getRandomNumber(20)); } if(Greenfoot.getRandomNumber(100)<5) { turn(Greenfoot.getRandomNumber(90)); } if(getX() <= 5 || getX() >= getWorld().getWidth() - 5) { turn(180); } if(getY() <= 5 || getY() >= getWorld().getWidth() - 5) { turn(180); } } public void spawnal() { if(Greenfoot.getRandomNumber(100) == 1) { int x = Greenfoot.getRandomNumber(400); int y = Greenfoot.getRandomNumber(300); addObject(new Worm(), x, y); } } }