Can anyone help me i really stuck for weeks with this problem
public void act(){
if(counter >= 20){
move(1);
counter = 0;
}else{
counter++
}
}public class Car extends Cars
{
Lives life;
private int timer = 100;
public Car(Lives liven){
life=liven;
}
public void act() {
checkMeter();
checkLives();
followroad();
placeroad();
atStation();
crashing();
checkEdges();
}
public void checkLives(){
if(life.getValue()== 2){
Greenfoot.stop();}
}
public void checkEdges() {
if(atWorldEdge()){
getWorld().removeObject(this);
if(getWorld() == null) return;
}
}
public void atStation(){
Actor car;
int pauseTimer=180;
car = getOneIntersectingObject(Station.class);
if (car!=null)
if (pauseTimer>0){
pauseTimer --;}
if (pauseTimer == 0)
setImage("car.png");
move(0);
}
private void checkMeter(){
if (timer > 0){
timer--;
if( timer == 0){
createNewVrachtSchip();
}
}
}
public void createNewVrachtSchip(){
World myWorld;
myWorld = getWorld();
int worldHeight = myWorld.getHeight();
int y = Greenfoot.getRandomNumber(worldHeight);
myWorld.addObject(new Car(live),100, y);
} sorry this is the car class
public class Car extends Cars
{
Lives life;
private int timer = 100;
public Car(Lives liven){
life=liven;
}
public void act() {
checkMeter();
checkLives();
followroad();
placeroad();
atStation();
crashing();
checkEdges();
}
public void checkLives(){
if(life.getValue()== 2){
Greenfoot.stop();}
}
public void checkEdges() {
if(atWorldEdge()){
getWorld().removeObject(this);
if(getWorld() == null) return;
}
}
public void atStation(){
Actor car;
int pauseTimer=180;
car = getOneIntersectingObject(Station.class);
if (car!=null)
if (pauseTimer>0){
pauseTimer --;}
if (pauseTimer == 0)
setImage("car.png");
move(0);
}
private void checkMeter(){
if (timer > 0){
timer--;
if( timer == 0){
createNewCar();
}
}
}
public void createNewCar(){
World myWorld;
myWorld = getWorld();
int worldHeight = myWorld.getHeight();
int y = Greenfoot.getRandomNumber(worldHeight);
myWorld.addObject(new Car(live),100, y);
}
public void crashing(){
Actor car;
car = getOneObjectAtOffset(0, 0, Car.class);
if (car != null){
getWorld().removeObject(car);
leven.add(1);
}
}
public boolean atWorldEdge() {
if(getX() < 10 || getX() > getWorld().getWidth() - 10)
return true;
if(getY() < 10 || getY() > getWorld().getHeight() - 10)
return true;
else
return false; }
public class Cars extends Actor
{
public void act()
{
}
private boolean carClicked()
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if(mouse.getActor()==this)
{
return true;
}
else return false;
}
public void followRoad()
{
Actor removethis = getOneIntersectingObject(Path.class);
int dist = 70;
Actor closest = null;
if(!getObjectsInRange(dist, Path.class).isEmpty())
{
for (Object obj: getObjectsInRange(dist, Path.class))
{
Actor car = (Actor) obj;
int carDist = (int) Math.hypot(car.getX() - getX(), car.getY() - getY());
if (closest == null || carDist< dist)
{
closest = car;
dist = carDist;
}
}
turnTowards(closest.getX(),closest.getY());
move(2);
if(closest.getY()>this.getY())
{
int newY = this.getY()+(1);
this.setLocation(getX(),newY);
}
else if(closest.getY()<this.getY())
{
int newY = this.getY()-(1);
this.setLocation(getX(),newY);
}
if (dist<70 && removethis !=null){
World world;
world = getWorld();
world.removeObject(removethis);
}
}
else if(getObjectsInRange(dist, Path.class).isEmpty())
{
move(2);
}
}
public void placeroad()
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if(mouse != null)
{
if (mouse.getButton() == 1 && carClicked()==true)
{
MouseInfo mousez = Greenfoot.getMouseInfo();
getWorld().addObject(new Path(), mousez.getX(), mousez.getY());
}
}
}public class Car extends Cars
{
Lives life;
int pauseTimer=180;
private int timer = 100;
public Car(Lives liven){
life=liven;
}
public void act() {
checkMeter();
checkLives();
followroad();
placeroad();
atStation();
crashing();
checkEdges();
}
public void checkLives(){
if(life.getValue()== 2){
Greenfoot.stop();}
}
public void checkEdges() {
if(atWorldEdge()){
getWorld().removeObject(this);
if(getWorld() == null) return;
}
}
public void atStation(){
Actor car;
car = getOneIntersectingObject(Station.class);
if (pauseTimer>0){
pauseTimer --;}
if (car!=null&&pauseTimer == 0){
setImage("car.png");
move(0);}
}
private void checkMeter(){
if (timer > 0){
timer--;
if( timer == 0){
createNewCar();
}
}
}
public void createNewCar(){
World myWorld;
myWorld = getWorld();
int worldHeight = myWorld.getHeight();
int y = Greenfoot.getRandomNumber(worldHeight);
myWorld.addObject(new Car(live),100, y);
}
public void crashing(){
Actor car;
car = getOneObjectAtOffset(0, 0, Car.class);
if (car != null){
getWorld().removeObject(car);
leven.add(1);
}
}
public boolean atWorldEdge() {
if(getX() < 10 || getX() > getWorld().getWidth() - 10)
return true;
if(getY() < 10 || getY() > getWorld().getHeight() - 10)
return true;
else
return false; }
} private void runAtStationTimer()
{
if (pauseTimer > 0)
{
pauseTimer--;
if (pauseTimer == 0)
{
setImage("car.png");
// play required sound
// anything else that needs done at this time
}
}
}private void atStation()
{
Actor station = getOneIntersectingObject(Station.class);
if (pauseTimer == 0 && station != null) // with possible other conditions
{
pauseTimer = 180;
}
}if (pauseTimer == 0)
{
followRoad();
placeRoad();
}// add instance field private boolean stoppedAtStation; // add condition to 'if' clause if (!stoppedAtStation && pauseTimer == 0 && station != null) // inside the 'if' block for the previous line, add stoppedAtStation = true;