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

2016/4/22

Online Score command

AngelusNeko13 AngelusNeko13

2016/4/22

#
hey, i was wondering... when i was finishing my scoreboard my teacher said that there was a certain command to add the score that players on Greenfoot could post automatically as highscores, i saw someone make a game that posts people's profile names with their highest scores beside their names and i wanted to know if there was a command to post online scores or at least some coding, here's the code to the highscore screen
import greenfoot.*;
import java.util.*;


 
public class End extends World
{

    static ArrayList<HighScore> highScores = new ArrayList<HighScore>();
        
    
    public End(int score)
    {    
      
        super(600, 600, 1);
        setPaintOrder(HighScore.class);
        addObject(new Reset(),300,550);
        HighScore newHS = new HighScore( score, "Player 1" );
        
        
            highScores.add(newHS);
            //System.out.println("Added first High Score.");
        
            Collections.sort(highScores);
            
        if ( highScores.isEmpty() )
        {
            //System.out.println("Empty High Scores!!");
        }
        else
        {
            for ( int i = 0; i < Math.min(8,highScores.size()); i++ )
            {
                HighScore hs = highScores.get(i);
                addObject( hs, getWidth()/2, 100 + 50*i  );
                //System.out.println("Added High Score "+i+" to screen: " + hs.score + ", " + hs.player );
            }
        }
danpost danpost

2016/4/22

#
There is a ScoreBoard class that you can import. From the menubar, select "Edit>Import class..." and choose the ScoreBoard class. It explains how to save high scores as well.
You need to login to post a reply.