I'm making a game for my computer programming class and I can't really figure out what to do about the score.
I want to make it so that when my predator class eats the egg class it will add something to the eggcounter.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class DinosaurWorld extends World
{
public DinosaurWorld()
{
super(560, 560, 1);
populateWorld();
getBackground().drawImage(new GreenfootImage("Instructions:", 20, null, null), 35, 1);
getBackground().drawImage(new GreenfootImage("Move the dinosaur using the space bar", 18, null, null), 40, 15);
getBackground().drawImage(new GreenfootImage("and turn using the up and down arrow keys.", 18, null, null), 50, 30);
}
int eggcounter = 0;
public void act()
{
getBackground().drawImage(new GreenfootImage("Score="+eggcounter, 20, null, null), 500, 500);
//when predator eats egg, eggcounter++
if (getObjects(Egg.class).isEmpty())
{
Greenfoot.stop();
}
}
public void populateWorld()
{
addObject(new predator(), 300, 300);
while (getObjects(Egg.class).size() < Greenfoot.getRandomNumber(11)){
addObject(new Egg(), Greenfoot.getRandomNumber(500), Greenfoot.getRandomNumber(500));
}
}
}
