Hello, I am having trouble figuring out how to make a live score board show the number of crates delivered to the depot. I do not understand how to get the number of crates to transfer to the counter class. I will post my code for my world, depot, and counter classes below.
World:
Counter;
Depot:
I have tried everything I can think of, and have made no progress. Any help is welcome! Thanks!
private void prepare()
{
Counter scoreCounter = new Counter();
addObject(scoreCounter, 59, 15);
Depot depot = new Depot(scoreCounter);
addObject(depot, 50, 62);
Crate crate = new Crate();
addObject(crate, 369, 101);
Crate crate2 = new Crate();
addObject(crate2, 201, 377);
Crate crate3 = new Crate();
addObject(crate3, 153, 191);
Barrier barrier = new Barrier();
addObject(barrier, 370, 244);
barrier.setLocation(397, 185);
Barrier barrier2 = new Barrier();
addObject(barrier2, 398, 286);
Barrier barrier3 = new Barrier();
addObject(barrier3, 398, 387);
Barrier barrier4 = new Barrier();
addObject(barrier4, 189, 291);
barrier4.setRotation(90);
Barrier barrier5 = new Barrier();
addObject(barrier5, 612, 296);
barrier5.setRotation(90);
Truck truck = new Truck();
addObject(truck, 63, 63);
truck.setRotation(0);
}
}public class Counter extends Actor
{
private GreenfootImage background;
private Color color;
private Color transparent;
public int score;
public Counter()
{
score=0;
background=getImage();
color=new Color(0,0,0,255);
transparent=new Color(0,0,0,0);
update();
}
/**
* Act - do whatever the Counter wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
update(); // Add your action code here.
}
public void update()
{
GreenfootImage image=new GreenfootImage(background);
GreenfootImage textScore=new GreenfootImage("Crates:"+ score, 22, color, transparent);
image.drawImage(textScore,10,3);
setImage(image);
}
public int getScore()
{
return score;
}
}public class Depot extends Cars
{
int score=0;
private Counter counter;
/**
* Depot Constructor
*/
public Depot(Counter scoreCounter)
{
counter=scoreCounter;
}
/**
* Act - do whatever the Depot wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (canSee(Crate.class)==true)
{
eat(Crate.class);
score++;
}
if (score>2)
{
}
}
public int getScore()
{
return score;
}
}

