I am having trouble showing the score on the endscreen even though the score is defined in endscreenworld class.
The endscreen displays 0 and novoice player instead of the final score.
Endscreen class
*************************************************************************************************************************
public class EndScreenWorld extends SimulationWorld
{
private GreenfootSound gameMusic;
/* (World, Actor, GreenfootImage, Greenfoot and MouseInfo)*/
/**
* Constructor for objects of class EndScreenWorld.
*/
public EndScreenWorld(double vscore)
{
super("", 800, 600, new Point2D(0.0, 0.0), 10);
gameMusic = new GreenfootSound("endMenu.wav");
Score result = new Score();
addObject(result, 400, 320);
result.setImage( new GreenfootImage("You finished with a score of " + (int)vscore + ".", 40, Color.WHITE, Color.BLACK, Color.YELLOW));
Score feedback = new Score();
addObject(feedback, 400, 380);
if (vscore >= 25 && vscore <= 75) {
String ranking = new String("intermediate player");
feedback.setImage( new GreenfootImage("You are a " + ranking + ".", 40, Color.BLUE, Color.BLACK, Color.YELLOW));
}
if (vscore < 25) {
String ranking = new String("novice player");
feedback.setImage( new GreenfootImage("You are a " + ranking + ".", 40, Color.BLUE, Color.BLACK, Color.YELLOW));
}
if (vscore > 75) {
String ranking = new String();
feedback.setImage( new GreenfootImage("You are a " + ranking + ".", 40, Color.BLUE, Color.BLACK, Color.YELLOW));
}
}
/**
*
*/
public void act()
{
if (Greenfoot.isKeyDown("space")) {
transitionToWorld( new StartScreenWorld());
}
}
/**
*
*/
public void started()
{
gameMusic.playLoop();
}
/**
*
*/
public void stopped()
{
gameMusic.stop();
}
}
Score class
*************************************************************************************************************************
public class Score extends Actor {
/* (World, Actor, GreenfootImage, Greenfoot and MouseInfo)*/
private double score = 0;
/**
* Act - do whatever the Score 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.*/
SimulationWorld world = (SimulationWorld)getWorld();
List<Bowl> bowls = world.getObjects(Bowl.class);
if (bowls.size() <= 0) {
return;
}
Bowl bowl = world.getObjects(Bowl.class).get(0);
if (bowl != null) {
/* score is set to current real position of the bowl (in space)*/
int scoregreen = bowl.greenApplesCounter * 1;
int scoreyellow = bowl.yellowApplesCounter * 3;
score = scoregreen + scoreyellow;
}
setImage( new GreenfootImage("Time(sec.): " + CatchWorld.currentGameTime + "\n\n Score: " + (int)score + " ", 22, Color.WHITE, Color.DARK_GRAY, Color.YELLOW));
}
/**
*
*/
public double getScore()
{
return score;
}
}
