HI, so at the end of my game I would like to be able to display my ScoreBoard with the player's final score on it. I'm not quite sure how I can carry this over?
*the end screen of my game is a separate world called EndWorld, and currently has nothing in it.
This is my code for my ScoreBoard class:
import greenfoot.*; import java.awt.Color; import java.awt.Graphics; { private int score = 0; private final int WIDTH = 80; private final int HEIGHT = 20; private String text = "Score: "; // This constructor creates the starting image for the Scoreboard public ScoreBoard() { GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT); image.setColor(Color.WHITE); image.fill(); image.setColor(Color.BLACK); image.drawRect(0, 0 , WIDTH - 1, HEIGHT - 1); setImage(image); updateDisplay(); } // This method reinstates the variable of score by adding the gained points with the current score. public void add(int value) { score = score + value; updateDisplay(); } // This method resets the score in the ScoreBoard back to 0. public void reset() { score = 0; updateDisplay(); } // This method gets the score from the actor CorrectDoor and returns it back. public int getScore() { return score; } // This method updates the display of the ScoreBoard with the scores from the CorrectDoor class. public void updateDisplay() { // x and y relative to the image. baseline of leftmost character. int x = 5; int y = 15; // "Repaint" the score display GreenfootImage image = getImage(); image.setColor(Color.WHITE); image.fillRect(1, 1, WIDTH-2, HEIGHT-2); // "erase" the display image.setColor(Color.BLACK); image.drawString(text + score, x, y); setImage(image); } }