I have a problem with making my final score in my game show in the second world called GameOver, my code for the counter is
And the code that adds score is
And my code for creating the new map is
And
Please if anyone could help, i have tried many different things but i cant get it to work
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * Write a description of class Counter1 here. * * @author (your name) * @version (a version number or a date) */ public class Counter1 extends Actor { int score = 0; /** * Act - do whatever the Counter1 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, Color.GREEN, Color.BLACK)); } public void addScore() { score++; } }
public void destroyEnemies() { Actor enemy = getOneIntersectingObject(Alien.class); if(enemy != null) { World myWorld = getWorld(); getWorld().removeObject(enemy); testWorld testworld = (testWorld)myWorld; Counter1 counter = testworld.getCounter(); counter.addScore(); getWorld().removeObject(this); Greenfoot.playSound("explosion.wav"); } }
public void Killed() { Actor enemy = getOneIntersectingObject(Alien.class); if(enemy != null) { getWorld().removeObject(enemy); getWorld().removeObject(this); Greenfoot.playSound("explosion.wav"); } }
if(getWorld().getObjects(Rocket.class).size() == 0) { music.stop(); Greenfoot.setWorld(new GameOver()); }