import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Font;
/**
* Write a description of class Counter here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Counter extends Actor
{
private boolean running = false;
private int millisElapsed = 0;
private long lastTime=0;
public GreenfootImage image99;
/**
* Act - do whatever the Counter wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Counter()
{
GreenfootImage image99 = getImage();
image99.scale(image99.getWidth() + 20, image99.getHeight() + 20);
updateImage();
}
public void start()
{
millisElapsed=0;
lastTime=0;
}
public void act()
{
long time = System.currentTimeMillis();
if(lastTime != 0)
{
long diff = time - lastTime;
millisElapsed += diff;
}
lastTime = time;
updateImage();
}
public void updateImage()
{
int millis= millisElapsed %1000;
int secs = (millisElapsed / 1000) %60;
int mins = millisElapsed / 60000;
String millisText = String.format("%03d", millis);
String secsText = String.format("%02d", secs);
String minsText = "" + mins;
String text = minsText + ":" + secsText + "." + millisText;
GreenfootImage img = new GreenfootImage(text, 25, null, null);
setImage(img);
}
public void changeCounterSize()
{
setImage(image99);
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import greenfoot.World;
import greenfoot.Actor;
import java.util.List;
/**
* Write a description of class Prey here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Prey extends Actor
{
/**
* Act - do whatever the Prey wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
turnDirection();
checkCollision();
}
public void turnDirection()
{
int speed = 5;
if(Greenfoot.isKeyDown("left"))
{
this.turn(-5);
}
if(Greenfoot.isKeyDown("right"))
{
this.turn(5);
}
if(Greenfoot.isKeyDown("up"))
{
move(speed);
}
}
public boolean collision()
{
Actor predator = getOneIntersectingObject(Predator.class);
return predator != null;
}
public void checkCollision()
{
if(collision())
{
Background background = (Background) getWorld();
Counter.changeCounterSize();
background.endGame();
}
}
}
