I have the board showing up fine but how can i make the board go away after the scenario delay is finished? Any help is appreciated :)
Space
Levelboard:
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
import java.util.Calendar;
/**
* The LevelBoard is used to display results on the screen. It can display some
* text and several numbers.
*
* @author M Kolling
* @version 1.0
*/
public class Levelboard extends Actor
{
public static final float FONT_SIZE = 48.0f;
public static final int WIDTH = 400;
public static final int HEIGHT = 300;
/**
* Create a level board with dummy result for testing.
*/
public Levelboard()
{
this(100);
}
/**
* Create a score board for the final result.
*/
public Levelboard(int score)
{
makeImage("Level Up", "Level: ", score);
}
/**
* Make the level up board image.
*/
private void makeImage(String title, String prefix, int score)
{
GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT);
int r = Greenfoot.getRandomNumber(256);
int g = Greenfoot.getRandomNumber(256);
int b = Greenfoot.getRandomNumber(256);
image.setColor(new Color(r,g,b, 128)); // setting a color
image.fillRect(0, 0, WIDTH, HEIGHT); // filiing the reactangle
image.setColor(new Color(r, g, b, 128));
image.fillRect(5, 5, WIDTH-10, HEIGHT-10); //smaller rectangle
Font font = image.getFont();
font = font.deriveFont(FONT_SIZE);
image.setFont(font);
image.setColor(Color.WHITE);
image.drawString(title, 60, 100);
image.drawString(prefix + score, 60, 200); //using string concatenation with the prefix + score line
setImage(image);
}
/**
*
*/
public void goAway()
{
Space space = (Space) getWorld();
space.removeObject(this);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
import java.util.List;
/**
* Space. Something for rockets to fly in.
*
* @author Michael Kolling
* @version 1.0
*/
public class Space extends World
{
private Counter scoreCounter;
private Counter levelCounter;
private int startAsteroids = 2;
public int asteroidNumber = 2;
public int round = 1;
private int startStars = 2500;
private boolean explosionFound;
HealthBar healthbar = new HealthBar();
public Space()
{
super(600, 400, 1);
GreenfootImage background = getBackground();//use this to add text, the first line before the equal sign
background.setColor(Color.BLACK);
background.fill();
addObject(healthbar, 518, 30);
Rocket rocket = new Rocket();
addObject(rocket, getWidth()/2 + 100, getHeight()/2);
addAsteroids(startAsteroids);
createStars(startStars);
//addAsteroids2(level2Asteroids);
scoreCounter = new Counter("Score: ");
addObject(scoreCounter, 60, 380);
// levelUpper = new Levelupp("Level: ");
// addObject (levelUpper, 580, 380);
levelCounter = new Counter("Level: ");
addObject(levelCounter, 540, 380);
levelCounter.add(1);
Explosion.initializeImages();
ProtonWave.initializeImages();
}
/**
* Add a given number of stars to our world..
*/
private void createStars(int number)
{
GreenfootImage background = getBackground();
for(int i = 0; i < number; i++)
{
int x = Greenfoot.getRandomNumber(getWidth());
int y = Greenfoot.getRandomNumber(getHeight());
int r = Greenfoot.getRandomNumber(256);
background.setColor(new Color(r,r,r));
//int g = Greenfoot.getRandomNumber(256);
//int b = Greenfoot.getRandomNumber(256);
//background.setColor(new Color(r,g,b));
background.fillOval(x, y, 4 , 4); //the two two controls the size of my stars!
//we add the same r value to make it gray if we would have many then we would get rainbow!
}
}
/**
* Add a given number of asteroids to our world. Asteroids are only added into
* the left half of the world.
*/
private void addAsteroids(int count)
{
for(int i = 0; i < count; i++)
{
int x = Greenfoot.getRandomNumber(getWidth()/2);
int y = Greenfoot.getRandomNumber(getHeight()/2);
addObject(new Asteroid(), x, y);
}
}
/**
* counts the score, everytime we hit an asteroid it goes up by the int
*/
public void countScore(int add)
{
scoreCounter.add(100);
// score += add;
}
/**
* to increase the # of asteroids after increase in levels
*/
public void nextRound(int add)
{
asteroidNumber += add;
if(asteroidNumber == 0)
{
round++;
levelCounter.add(1);
addAsteroids(round + 1);
asteroidNumber = round + 1;
List<Rocket> rockets = getObjects(Rocket.class);
for ( Rocket rocket : rockets )
{
rocket.next();
}
levelUp();
Greenfoot.delay(80);
}
}
/**
* this is to get our healthbar info back!
*/
public HealthBar getHealthBar()
{
return healthbar;
}
/**
* if Explosion occurs then game over, if it doesn't, continue
*/
public void act()
{
if (!explosionFound && !getObjects(Explosion.class).isEmpty()) explosionFound = true;
if (explosionFound && getObjects(Explosion.class).isEmpty()) gameOver();
}
/**
* This method is called when the player has leveled up to display the new level.
*/
public void levelUp()
{
addObject(new Levelboard(levelCounter.getValue()), getWidth()/2, getHeight()/2); // the coordinates div
// TODO: show the score board here. Currently missing.
}
/**
* This method is called when the game is over to display the final score.
*/
public void gameOver()
{
addObject(new ScoreBoard(scoreCounter.getValue()), getWidth()/2, getHeight()/2); // the coordinates div
// TODO: show the score board here. Currently missing.
}
}

