I have a separate screen for when the game ends. I would like to display the score in my end screen. How can I do it?
public class Counter extends Actor. I want it to appear on my GameOverScreen
{
int score = 0;
/**
* 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()
{
setImage(new GreenfootImage("Score : " + score, 24, greenfoot.Color.RED, greenfoot.Color.BLACK));
}
public void addScore()
{
score++;
}
}public class GameScreen extends World
{
private int delay = 0;
Counter counter = new Counter();
public int lifeCounter = 3;
private Lives lives1;
private Lives lives2;
private Lives lives3;
/**
* Constructor for objects of class GameScreen.
*
*/
public GameScreen()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1, false);
prepare();
}
public Counter getCounter()
{
return counter;
}public class Laser extends Actor
{
public void act()
{
if(!toRemove)
{
setLocation(getX()+vx,getY());
Actor actor=getOneIntersectingObject(Enemy.class);
if(actor!=null)
{
GameScreen gameScreen = (GameScreen)getWorld();
Counter counter = gameScreen.getCounter();
counter.addScore();
((Enemy)actor).destroyed();
Greenfoot.playSound("Explosion.wav");
}
}
