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

2018/6/30

Help in Score addition

kukusls kukusls

2018/6/30

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class Highscore here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Highscore extends Actor
{
    long startZeit = System.currentTimeMillis();
    gameover welt = null;

    public void act() 
    {
        paint();
        Greenfoot.stop();
    }

    public void paint()
    { 
        long aktZeit = System.currentTimeMillis();
        int sekunden = Math.round((aktZeit-startZeit)/1000);
        int aktHighscore = (sekunden+MyWorld.collectablesCount);
        GreenfootImage newImage = new GreenfootImage ("Score: " + aktHighscore, 25, Color.WHITE, null);
        this.setImage(newImage);
    }
}
That is my Score class which should be shown up on the enscreen(called gameover) aktHighscore should be an addition of "sekunden" and "MyWorld.collectablesCount" but it only shows up the MyWorld.collectablesCount Here my scoreboard class:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class Scoreboard here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Scoreboard extends Actor
{
    MyWorld welt = null;
    long startZeit = System.currentTimeMillis();
    int sekunden = 0;

    public Scoreboard(MyWorld pWelt){
        welt = pWelt;
    }

    public void act() 
    {
        repaint();
    }    

    public void repaint() {
        long aktZeit = System.currentTimeMillis();
        int sekunden = Math.round((aktZeit-startZeit)/1000);

        GreenfootImage newImage = new GreenfootImage ("Zeit: " +  sekunden + " | Punkte: " + MyWorld.collectablesCount, 25, Color.WHITE, null);
        this.setImage(newImage);

    }
}
Furthermore, my Collectablescounter does acutally not reset when you press the Reset button in greenfoot and I dunno why Someone can help me?
danpost danpost

2018/6/30

#
kukusls wrote...
<< Code Omitted >> That is my Score class which should be shown up on the enscreen(called gameover) aktHighscore should be an addition of "sekunden" and "MyWorld.collectablesCount" but it only shows up the MyWorld.collectablesCount Here my scoreboard class: << Code Omitted >> Furthermore, my Collectablescounter does acutally not reset when you press the Reset button in greenfoot and I dunno why Someone can help me?
You need to create a retain a Highscore object in your world and add it to the world when game is over (otherwise the start time will be the end time (if you create it and immediately at it into the world). Your collectablesCount field is probably static. You must initially any static fields that need initializing every game in your world constructor.
You need to login to post a reply.