Need help with finding how to transfer same score in the main game to the win screen
This code is for win screen:
This code is for MyWorld:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MyWorld extends World
{
SimpleTimer time = new SimpleTimer();
Timer con = new Timer();
Counter counter = new Counter();
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
public MyWorld()
{
super(600, 400, 1);
addObject(counter, 525, 30);
addObject(con,40,30);
Ship ship = new Ship();
addObject(ship,309,200);
Alien alien = new Alien();
addObject(alien,562,42);
Alien alien2 = new Alien();
addObject(alien2,556,208);
Alien alien3 = new Alien();
addObject(alien3,553,370);
Alien alien4 = new Alien();
addObject(alien4,18,370);
Alien alien5 = new Alien();
addObject(alien5,24,194);
Alien alien6 = new Alien();
addObject(alien6,27,27);
removeObject(alien2);
removeObject(alien5);
time.mark();
}
public void newAlien()
/**
* This code makes the ship spawn in the middle and the 6 aliens spawn around the edge
*/{
addObject(new Alien(),Greenfoot.getRandomNumber(300),Greenfoot.getRandomNumber(300));
}
public void act()
{
con.setValue(time.millisElapsed() / 1000);
if(time.millisElapsed() >= 90000){
Greenfoot.setWorld( new WinScreen());
}
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
public Counter getCounter()
{
return counter;
}
}
And this code is for my counter
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Counter here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Counter extends Actor
{
int score = 0;
/**
* Act - do whatever the Counter 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.WHITE, Color.BLACK));
}
public void addScore()
{
score++;
}
}
Please reply ASAP thanks
:)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class WinScreen here. * * @author (your name) * @version (a version number or a date) */ public class WinScreen extends World { Counter counter = new Counter(); /** * Constructor for objects of class WinScreen. * */ public WinScreen() { super(600, 400, 1); addObject(counter, 525, 30); } }