import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* Write a description of class Timer here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Timer extends Actor
{
/**
* Act - do whatever the Timer wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public int time = 20;
public int count = 65;
public void act()
{
if(time==0)
{
addText("Time Up");
Greenfoot.stop();
return;
}
if(counter())
{
time--;
count =65;
}
display();
}
public boolean counter()
{
if(count>0)
{
count--;
}
return count==0;
}
public void display()
{
setImage(new GreenfootImage("Time left: "+time,30,Color.RED,Color.BLACK));
}
public void setTime()
{
time = 20;
}
public boolean isTimeUp()
{
return time ==0;
}
public void addText(String message) {
addObject(new Message(message), getWidth()/2, getHeight()/2);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* Write a description of class Text here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Message extends Actor
{
public Message(String message) {
setImage(new GreenfootImage(message,50, Color.RED, Color.WHITE));
}
/**
* Act - do whatever the Text wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
}
}

