Hi!
I need your help. I want my timer to count up when the GameOverclass is empty and the Grapeclass is not empty.
The part with the GameOverclass works, but not the part with the Grapeclass.
I tried this:
Can you help me please?
Thx,
Fifilein
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* Write a description of class frogfly here.
*
* @author (Fifilein)
* @version (2.4)
*/
public class frogfly extends World
{
Counter counter = new Counter();
private int timer;
private Actor timerDisplay;
Grape g = new Grape();
/**
* Constructor for objects of class frogfly.
*
*/
public frogfly()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
timer = 1;
timerDisplay = new SimpleActor();
addObject(timerDisplay, 220, 20); // change location as desired
updateTimerDisplay(); //Button endles = new Buttony(300, 100, 0);
//
// addObject(new Grape(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(600));
//}
int x = Greenfoot.getRandomNumber(10);
for (int i = 2; i<=x; i++){
addObject(new Grape(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(600));
}
addObject(new Lobster(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(600));
addObject(new Hippo(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(600));
addObject(counter, 100, 40);
}
public void act()
{
//if (g != null)
if (timer > 0 && getObjects(GameOver.class).isEmpty() && g != null)
{ timer++; if (timer%60 == 0) {
updateTimerDisplay(); }
}
}
private void updateTimerDisplay()
{timerDisplay.setImage(new GreenfootImage("Time remaining: "+(timer/60), 24, Color.RED, new Color(0, 0, 0, 0))); // adjust text as desired
}
public Counter getCounter()
{
return counter;
}
}

