This site requires JavaScript, please enable it in your browser!
Greenfoot back

Discussions

You need to login to take part
Rss

Current Discussions

bbishal69

About Green foot

By bbishal69, with no replies.
Add new asteroids when all have been cleared. Maybe the game should start with just two asteroids, and every time they are cleared away, new ones appear, one more every time. So in the second round, there are three asteroids, in the third round four, and so on. You will have a chance to use generic programming, such as List<>. My code: import greenfoot.*; /** * Space. Something for rockets to fly in. * * @author Michael K├Âlling * @version 1.2 */ public class Space extends World { private Counter scoreCounter; private int startAsteroids = 2; /** * Create the space and all objects within it. */ public Space() { super(600, 500, 1); GreenfootImage background = getBackground(); background.setColor(Color.BLACK); background.fill(); createStars(300); Rocket rocket = new Rocket(); addObject(rocket, getWidth()/2 + 100, getHeight()/2); addAsteroids(startAsteroids); scoreCounter = new Counter("Score: "); addObject(scoreCounter, 60, 480); Explosion.initializeImages(); ProtonWave.initializeImages(); } /** * 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); } } /** * Crete a given number of stars in space. */ 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 color = 120 - Greenfoot.getRandomNumber(100); background.setColor(new Color(color,color,color)); background.fillOval(x, y, 2, 2); } } /** * 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); } /** * This method passed parameter as count of the score */ public void countScore(int count) { /* call the Counter class with method to add score counting */ scoreCounter.add(count); } public void leftOver() { List<Asteroid> leftOver = addObjects(50,Asteroid.class); //Stuck here to call the asteroid!!!! Please help me. Thank you }
1
2
3
4
5
6
7