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

2017/3/7

Show score at the end

JokeNotFound JokeNotFound

2017/3/7

#
                       private void prepare()
{
    time = 3300;
    //adding objects here
}
            
            public void act()
    {
         if (time%55 == 0) showText(""+(time/55), 50, 50);
           
        time--;
    if (time == -1)
       {
        removeObjects(getObjects(null));
        setBackground("gameoverscreen.png");
        
        Greenfoot.stop();
   
        
        
       }
So this partially my timer. When it reaches time=0 the world stops. Now i want to display the achieved Points of the scoreboard. It disappears because of
Greenfoot.stop();
   
Is there any way to display the score at the end
OKNEM OKNEM

2017/3/7

#
I've got the exact same problem, but this is my code:
public void adjustHealth(int changeAmount)
    {
        health += changeAmount;
        if (health > 5) health = 5;
        if (health < 0) health = 0;
        healthbar.setImage("health"+health+".png");
        if (health == 0)
        {
            removeObjects(getObjects(null));
            setBackground("wowgameover.jpg");
        }
    }
And I want to set the number as my "value" variable in Counter class.
danpost danpost

2017/3/7

#
JokeNotFound wrote...
< Code Omitted > Is there any way to display the score at the end
Where and how is the score field declared? Show class code where located.
danpost danpost

2017/3/7

#
OKNEM wrote...
I've got the exact same problem, but this is my code: < Code Omitted > And I want to set the number as my "value" variable in Counter class.
Please start a new discussion for your issue.
JokeNotFound JokeNotFound

2017/3/8

#
The Scoreboard consists of a class
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
public class ScoreBoard extends Actor
{
   /**
     * Act - do whatever the ScoreBoard wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() {
        
    }    
    
    public void edit(int treffer) {
        setImage(new GreenfootImage(treffer + " Treffer", 25, Color.WHITE, Color.BLACK));
    }
}
also in MyWorld
public class MyWorld extends World
{
public ScoreBoard sb;
public MyWorld()
    {    sb = new ScoreBoard();
        addObject(sb, 50, 20);
}
danpost danpost

2017/3/9

#
JokeNotFound wrote...
So this partially my timer. When it reaches time=0 the world stops. Now i want to display the achieved Points of the scoreboard. It disappears because of
Greenfoot.stop();
Is there any way to display the score at the end
Actually, it disappears because of this:
removeObjects(getObjects(null));
But, no need to fret because you still have a reference to the ScoreBoard object (line 3 in your last code snippet -- 'public ScoreBoard sb;' -- which is asigned the ScoreBoard object before placing that object in the world.. You can add the object right back into the world by adding a copy of the last line you posted (line 6) immediately after the line that actually made it disappear.
JokeNotFound JokeNotFound

2017/3/9

#
Thank you very much, it worked!!
You need to login to post a reply.