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

2018/1/17

HighScore Board

1
2
GethEvs GethEvs

2018/1/17

#
I am currently working on a school project for my own benefit. I have designed a Flappy Bird Game, I am now attempting to include a highscore board. I have attempted to use the imported ScoreBoard from greenfoot classes, however with the newest version of greenfoot. This imported Scoreboard no longer works due to an update in greenfoot adjusting the font and color changes. I was wondering if there is a way to fix the imported scoreboard, or if there is a simpler way to implement a highscore board. Thank you.
CxVercility CxVercility

2018/1/17

#
When starting a greenfoot project with said errors, greenfoot should offer you to replace old methods automatically (that's what happened with my old school project) actually.. Else u can just look up the current methods used by greenfoot and choose your own colors or just use an older greenfoot version (3.0.4 and below) https://www.greenfoot.org/doc/font_color
danpost danpost

2018/1/17

#
The first step in making the class compatible with the new version of greenfoot is removing the Color and Font import lines (or any java.awt import lines). Any other problems will then be highlighted and should be easy enough to fix. Keep in mind that NO color parameters can be 'null' and must be replaced with a true Color value.
GethEvs GethEvs

2018/1/24

#
danpost wrote...
The first step in making the class compatible with the new version of greenfoot is removing the Color and Font import lines (or any java.awt import lines). Any other problems will then be highlighted and should be easy enough to fix. Keep in mind that NO color parameters can be 'null' and must be replaced with a true Color value.
Upon removing the 'java.awt.Color' import line it has highlighted only one error in my code,
private void drawString(String text, int x, int y, Color color, int height)
    {
        getImage().drawImage(new GreenfootImage(text, height, color, new Color (0, true)), x, y);
    }
I have looked into this error and have so far I have not been able to think of anyway to fix it nor found anything that will help, if you can think of anyway to fix the error it will be much appreciated. Thank you
GethEvs GethEvs

2018/1/24

#
CxVercility wrote...
When starting a greenfoot project with said errors, greenfoot should offer you to replace old methods automatically (that's what happened with my old school project) actually.. Else u can just look up the current methods used by greenfoot and choose your own colors or just use an older greenfoot version (3.0.4 and below) https://www.greenfoot.org/doc/font_color
I have removed the 'java.awt.Color' import and upon doing this it has highlighted only one error in my code. however greenfoot has not offered to replace the old methods and I am unsure how I am able to access this option. The message that is being displayed in the current error is: "no suitable constructor found for Color (int,boolean) constructor greenfoot.Color.Color(java.awt.Color) is not applicable (actual and formal argument lists differ in length)" If you could explain how the option given by greenfoot to replace the old methods it would be much appreciated. Thank you.
CxVercility CxVercility

2018/1/24

#
Hey, The color constructor looks as follows
Color(int r, int g, int b)
Creates a RGB color with the specified red, green, blue values in the range (0 - 255).
Alpha can be added after b, also as an int if required. https://www.rapidtables.com/web/color/RGB_Color.html
Super_Hippo Super_Hippo

2018/1/24

#
Instead of 'new Color(0, true)', you can use 'new Color(0,0,0,0)' to create a transparent color.
GethEvs GethEvs

2018/1/24

#
CxVercility wrote...
Hey, The color constructor looks as follows
Color(int r, int g, int b)
Creates a RGB color with the specified red, green, blue values in the range (0 - 255).
Alpha can be added after b, also as an int if required. https://www.rapidtables.com/web/color/RGB_Color.html
Thank You! I will give it a go.
GethEvs GethEvs

2018/1/31

#
I have been attempting for to implement changes to the code, adding the color constructor and so on. Yet I am still unable to fix the issues/work around them. I am not awfully experienced so perhaps this is the issue at hand and I simply can not see a simple issue, but any help would be very much appreciated
Super_Hippo Super_Hippo

2018/1/31

#
Show what you have tried, so we can try to help you.
GethEvs GethEvs

2018/1/31

#
Super_Hippo wrote...
Show what you have tried, so we can try to help you.
I have gone back to the final point I feel I was closest to having it working in my opinion. I will show what I currently have, I feel it is as close if not closer to working to when i attempted to implement the color constructor.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;

/**
 * An actor class that can display a scoreboard, using Greenfoot's
 * UserInfo class.  
 * 
 * You typically use this by including some code into the world for when your game ends:
 * 
 * <pre>
 *   addObject(new ScoreBoard(800, 600), getWidth() / 2, getHeight() / 2); 
 * </pre>
 * 
 * Where 800 by 600 should be replaced by the desired size of the score board. 
 * 
 * @author Neil Brown 
 * @version 1.0
 */
public class ScoreBoard extends Actor
{
    // The vertical gap between user images in the scoreboard:
    private static final int GAP = 10;
    // The height of the "All Players"/"Near Me" text at the top:
    private static final int HEADER_TEXT_HEIGHT = 25;
    // The main text color:
    private static final Color MAIN_COLOR = new Color(0x60, 0x60, 0x60); // dark grey
    // The score color:
    private static final Color SCORE_COLOR = new Color(0xB0, 0x40, 0x40); // orange-y
    // The background colors:
    private static final Color BACKGROUND_COLOR = new Color(0xFF, 0xFF, 0xFF, 0xB0);
    private static final Color BACKGROUND_HIGHLIGHT_COLOR = new Color(180, 230, 255, 0xB0);

    /**
     * Constructor for objects of class ScoreBoard.
     * <p>
     * You can specify the width and height that the score board should be, but
     * a minimum width of 600 will be enforced.
     */
    public ScoreBoard(int width, int height)
    {    
        setImage(new GreenfootImage(Math.max(600, width), height)); 
        
        drawScores();
    }
    
    private void drawString(String text, int x, int y, Color color, int height)
    {
        getImage().drawImage(new GreenfootImage(text, height, color, new Color (0, true)), x, y);
    }
    
    private void drawScores()
    {
        // 50 pixels is the max height of the user image
        final int pixelsPerUser = 50 + 2*GAP;
        // Calculate how many users we have room for:
        final int numUsers = ((getImage().getHeight() - (HEADER_TEXT_HEIGHT + 10)) / pixelsPerUser);
        final int topSpace = getImage().getHeight() - (numUsers * pixelsPerUser) - GAP;
        
        getImage().setColor(BACKGROUND_COLOR);
        getImage().fill();

        drawString("All Players", 100, topSpace - HEADER_TEXT_HEIGHT - 5, MAIN_COLOR, HEADER_TEXT_HEIGHT);
        drawString("Near You", 100 + getImage().getWidth() / 2, topSpace - HEADER_TEXT_HEIGHT - 5, MAIN_COLOR, HEADER_TEXT_HEIGHT);        
        
        drawUserPanel(GAP, topSpace, (getImage().getWidth() / 2) - GAP, topSpace + numUsers * pixelsPerUser, UserInfo.getTop(numUsers));
        drawUserPanel(GAP + getImage().getWidth() / 2, topSpace, getImage().getWidth() - GAP, topSpace + numUsers * pixelsPerUser, UserInfo.getNearby(numUsers));
    }
    
    private void drawUserPanel(int left, int top, int right, int bottom, List users)
    {
        getImage().setColor(MAIN_COLOR);
        getImage().drawRect(left, top, right - left, bottom - top);
        
        if (users == null)
            return;
        
        UserInfo me = UserInfo.getMyInfo();
        int y = top + GAP;
        for (Object obj : users)
        {
            UserInfo playerData = (UserInfo)obj;            
            Color c;
            
            if (me != null && playerData.getUserName().equals(me.getUserName()))
            {
                // Highlight our row in a sky blue colour:
                c = BACKGROUND_HIGHLIGHT_COLOR;
            }
            else
            {
                c = BACKGROUND_COLOR;
            }
            getImage().setColor(c);
            getImage().fillRect(left + 5, y - GAP + 1, right - left - 10, 50 + 2*GAP - 1);

            int x = left + 10;
            drawString("#" + Integer.toString(playerData.getRank()), x, y+18, MAIN_COLOR, 14);
            x += 50;
            drawString(Integer.toString(playerData.getScore()), x, y+18, SCORE_COLOR, 14);
            x += 80;
            getImage().drawImage(playerData.getUserImage(), x, y);
            x += 55;
            drawString(playerData.getUserName(), x, y + 18, MAIN_COLOR, 14);
            y += 50 + 2*GAP;
        }
    }
}
Thank you for your time :)
Super_Hippo Super_Hippo

2018/1/31

#
As always: What is happening? How is it different to what should happen? Do you receive any error message? I am not at home right now, so I don't have access to Greenfoot and can't see the differences between your code and the scoreboard class that you import. Why do you use 0x60 (and other hex numbers) there instead of simple ints?
GethEvs GethEvs

2018/1/31

#
I have pretty much gone back to the imported one, The error message being displayed is this "no suitable constructor found for Color (int boolean) constructor greenfoot.Color.Color(java.awt.Color ) is not applicable (actual and formal argument lists differ in length ) "
danpost danpost

2018/1/31

#
Change the hexadecimal values (values beginning with '0x') to decimal values. With each, remove the '0x', then take the last digit and add to it 16 times the second to last digit. The alpha digits start with A being 10, going up to F being 15.
GethEvs GethEvs

2018/2/5

#
danpost wrote...
Change the hexadecimal values (values beginning with '0x') to decimal values. With each, remove the '0x', then take the last digit and add to it 16 times the second to last digit. The alpha digits start with A being 10, going up to F being 15.
I have completed these changes, what is the next thing that I need to change?
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;

/**
 * An actor class that can display a scoreboard, using Greenfoot's
 * UserInfo class.  
 * 
 * You typically use this by including some code into the world for when your game ends:
 * 
 * <pre>
 *   addObject(new ScoreBoard(800, 600), getWidth() / 2, getHeight() / 2); 
 * </pre>
 * 
 * Where 800 by 600 should be replaced by the desired size of the score board. 
 * 
 * @author Neil Brown 
 * @version 1.0
 */
public class ScoreBoard extends Actor
{
    // The vertical gap between user images in the scoreboard:
    private static final int GAP = 10;
    // The height of the "All Players"/"Near Me" text at the top:
    private static final int HEADER_TEXT_HEIGHT = 25;
    // The main text color:
    private static final Color MAIN_COLOR = new Color(6, 6, 6); // dark grey
    // The score color:
    private static final Color SCORE_COLOR = new Color(11, 4, 4); // orange-y
    // The background colors:
    private static final Color BACKGROUND_COLOR = new Color(255, 255, 255, 11);
    private static final Color BACKGROUND_HIGHLIGHT_COLOR = new Color(180, 230, 255, 11);

    /**
     * Constructor for objects of class ScoreBoard.
     * <p>
     * You can specify the width and height that the score board should be, but
     * a minimum width of 600 will be enforced.
     */
    public ScoreBoard(int width, int height)
    {    
        setImage(new GreenfootImage(Math.max(600, width), height)); 
        
        drawScores();
    }
    
    private void drawString(String text, int x, int y, Color color, int height)
    {
        getImage().drawImage(new GreenfootImage(text, height, color, new Color (0, true)), x, y);
    }
    
    private void drawScores()
    {
        // 50 pixels is the max height of the user image
        final int pixelsPerUser = 50 + 2*GAP;
        // Calculate how many users we have room for:
        final int numUsers = ((getImage().getHeight() - (HEADER_TEXT_HEIGHT + 10)) / pixelsPerUser);
        final int topSpace = getImage().getHeight() - (numUsers * pixelsPerUser) - GAP;
        
        getImage().setColor(BACKGROUND_COLOR);
        getImage().fill();

        drawString("All Players", 100, topSpace - HEADER_TEXT_HEIGHT - 5, MAIN_COLOR, HEADER_TEXT_HEIGHT);
        drawString("Near You", 100 + getImage().getWidth() / 2, topSpace - HEADER_TEXT_HEIGHT - 5, MAIN_COLOR, HEADER_TEXT_HEIGHT);        
        
        drawUserPanel(GAP, topSpace, (getImage().getWidth() / 2) - GAP, topSpace + numUsers * pixelsPerUser, UserInfo.getTop(numUsers));
        drawUserPanel(GAP + getImage().getWidth() / 2, topSpace, getImage().getWidth() - GAP, topSpace + numUsers * pixelsPerUser, UserInfo.getNearby(numUsers));
    }
    
    private void drawUserPanel(int left, int top, int right, int bottom, List users)
    {
        getImage().setColor(MAIN_COLOR);
        getImage().drawRect(left, top, right - left, bottom - top);
        
        if (users == null)
            return;
        
        UserInfo me = UserInfo.getMyInfo();
        int y = top + GAP;
        for (Object obj : users)
        {
            UserInfo playerData = (UserInfo)obj;            
            Color c;
            
            if (me != null && playerData.getUserName().equals(me.getUserName()))
            {
                // Highlight our row in a sky blue colour:
                c = BACKGROUND_HIGHLIGHT_COLOR;
            }
            else
            {
                c = BACKGROUND_COLOR;
            }
            getImage().setColor(c);
            getImage().fillRect(left + 5, y - GAP + 1, right - left - 10, 50 + 2*GAP - 1);

            int x = left + 10;
            drawString("#" + Integer.toString(playerData.getRank()), x, y+18, MAIN_COLOR, 14);
            x += 50;
            drawString(Integer.toString(playerData.getScore()), x, y+18, SCORE_COLOR, 14);
            x += 80;
            getImage().drawImage(playerData.getUserImage(), x, y);
            x += 55;
            drawString(playerData.getUserName(), x, y + 18, MAIN_COLOR, 14);
            y += 50 + 2*GAP;
        }
    }
}
There are more replies on the next page.
1
2