I'm new to Greenfoot (Programming in general aswell) and trying to make a Simple Game where an Ant eats Food and that way its Score gets higher.
I'm now trying to make the chance of Food Spawning randomly, which I have coded in the MyWorld class, dependant on the 'Score' variable from the Ant class (or set global Variables in the World class which can be changed by Actor classes).
Below is the code I have in the MyWorld class, and I will gladly send the code of the Ant class if that is needed.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class MyWorld extends World { int Chance = 1; public MyWorld() { super(1000, 800, 1); prepare(); } public void act() { SpawnStuff(); if(Greenfoot.getRandomNumber(250) == 1) { Chance = (Chance + 1); } } private void prepare() { addObject(new AntPlayer(), 100, 100); addObject(new FoodGood(), 300, 300); } public void SpawnStuff() { if(Greenfoot.getRandomNumber(150) == Chance) { int x = Greenfoot.getRandomNumber(990); int y = Greenfoot.getRandomNumber(790); addObject(new FoodGood(), x, y); } } }