hello there
@danpost can you plz or anybody else comment the code above for me??
i.e timer class
import greenfoot.*;
import java.awt.Color;
/**
* an object that display the remaining time before the scenario stops
*/
public class Timer extends Actor
{
long initialTime = System.currentTimeMillis(); // the start time
int elapsedTime = 0; // to hold the elapsed time in milliseconds (1/1000th of a second)
/*
* sets the initial image of this Timer object
*/
public Timer()
{
updateImage(); // shows remaining time
}
/*
* runs the timer and updates the image of this Timer object
*/
public void act()
{
elapsedTime = System.currentTimeMillis() - initialTime; // compute elapsed time
updateImage(); // show the time remaining
if (elapsedTime >= 60000) ((BackGround) getWorld()).gameOver(); // after 60 seconds, stop the scenario
}
/*
* sets the image to the number of seconds remaining on the timer
*/
private void updateImage()
{
setImage(new GreenfootImage("" + ((int) ((60000 - elapsedTime)) / 1000), 24, Colour.BLACK, new Color(0, 0, 0, 0)));
}
}import greenfoot.*;
import java.awt.Color;
/**
* an object that display the remaining time before the scenario stops
*/
public class Timer extends Actor
{
long initialTime = System.currentTimeMillis(); // the start time
int elapsedTime = 0; // to hold the elapsed time in milliseconds (1/1000th of a second)
/*
* sets the initial image of this Timer object
*/
public Timer()
{
updateImage(); // shows remaining time
}
/*
* runs the timer and updates the image of this Timer object
*/
public void act()
{
elapsedTime = System.currentTimeMillis() - initialTime; // compute elapsed time
updateImage(); // show the time remaining
if (elapsedTime >= 60000) ((BackGround) getWorld()).gameOver(); // after 60 seconds, stop the scenario
}
/*
* sets the image to the number of seconds remaining on the timer
*/
private void updateImage()
{
setImage(new GreenfootImage("" + ((int) ((60000 - elapsedTime)) / 1000), 24, Colour.BLACK, new Color(0, 0, 0, 0)));
}
}import greenfoot.*;
import java.awt.Color;
/**
* an object that display the remaining time units before the scenario stops;
* this class counts frames (or act cycles) as the regulating unit of time
*/
public class Timer extends Actor
{
int time = 90; // seconds to run
int fps = 55; // approximate number of frames per second (adjust as needed)
int cycles = time * fps; // the countdown timer
/*
* sets the initial image of this Timer object
*/
public Timer()
{
updateImage(); // shows remaining time
}
/*
* runs the timer and updates the image of this Timer object
*/
public void act()
{
cycles--; // decrement countdown timer
if (cycles % fps == 0) updateImage(); // show the time remaining (only done when needed)
if (cycles == 0) ((BackGround) getWorld()).gameOver(); // when countdown completes, stop the scenario
}
/*
* sets the image to the number of approximate seconds remaining on the timer
*/
private void updateImage()
{
setImage(new GreenfootImage("" + (cycles+fps-1)/fps, 24, Colour.BLACK, null));
}
}