import greenfoot.*;
/**
* Write a description of class Car3 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Car3 extends Animal
{
/**
* Act - do whatever the Car3 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
KeyPress();
consumeFuel();
hitcar();
}
void KeyPress()
{
if(Greenfoot.isKeyDown("left"))
{
move(-4);
}
if(Greenfoot.isKeyDown("right"))
{
move(4);
}
if(Greenfoot.isKeyDown("up"))
{
turn(4);
}
if(Greenfoot.isKeyDown("down"))
{
turn(-4);
}
}
void consumeFuel()
{
if(canSee(Fuel.class));
{
eat(Fuel.class);
}
}
void hitcar()
{
if(canSee(Dot.class))
{
eat(Dot.class);
Greenfoot.playSound("Blast.mp3");
Greenfoot.stop();
}
}
Show codes where you add Fuel actors into the world. From what I can tell so far, only by adding an abundance of them would cause the sound to play repeatedly.
import greenfoot.*;
/**
* Write a description of class Fuel here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Fuel extends Animal
{
/**
* Act - do whatever the Fuel 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.
}
}
this is the code of the fuel which it is eating and no other actor can catch it