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

2018/1/14

High score System

1
2
3
Dimak Dimak

2018/1/14

#
일리아스 wrote...
If you dont even care how can you expect us to care? Besides I checked that guys project and I can see that you literally copy pasted his HighScore class. Its not about doing something different. Its about doing it yourself. Putting a thought or two in something. Anyways. Tell the teacher your thoughts and enjoy building your robot. I refuse to help you, sorry.
Checked who's project? Cause I used the Greenfoot UserInfo Api (which contains the exact code as mine) in the project.
xbLank xbLank

2018/1/14

#
I was talking about your general code structure and other methods such as "setHighScore" and"setScore". Stop bullshitting me.
Dimak Dimak

2018/1/14

#
Are you serious right now? That is my game right there, I am pretty confused at this point. Edit: check my account if you want to see it
xbLank xbLank

2018/1/14

#
At this point i am seriously confused.
xbLank xbLank

2018/1/14

#
But its actually funny to be honest.
Dimak Dimak

2018/1/14

#
일리아스 wrote...
But its actually funny to be honest.
Indeed... Well... this is awkward now. Edit: did you not see who uploaded it lol?
xbLank xbLank

2018/1/14

#
When you said "a game like asteroidz" I thought you were refering to a project that was not made by you. It could have been helpful to check the name.
xbLank xbLank

2018/1/14

#
Anyways. Basically forget anything I just said. My apologies.
Dimak Dimak

2018/1/14

#
Well anyways thanks for your help
Dimak Dimak

2018/1/14

#
일리아스 wrote...
Anyways. Basically forget anything I just said. My apologies.
This was a highlight of my day, thanks for taking me on an emotional rollercoaster
xbLank xbLank

2018/1/14

#
LOL. At least something.
danpost danpost

2018/1/14

#
On the other hand, it may not be best to have a UserInfo field as you cannot tell from one moment to the next if the server will be accessible. So, here is how I might code it:
import greenfoot.*;

public class HighScore extends Actor
{
    int highScore = 0;
    
    public HighScore()
    {
        if (UserInfo.isStorageAvailable())
        {
            UserInfo myInfo = UserInfo.getMyInfo();
            highScore = myInfo.getScore();
        }
        draw();
    }
    
    public void setHighScore(int newScore)
    {
        if (newScore > highScore)
        {
            highScore = newScore;
            if (UserInfo.isStorageAvailable())
            {
                UserInfo myInfo = UserInfo.getMyInfo();
                if (highScore > myInfo.getScore())
                {
                    myInfo.setScore(highScore);
                    myInfo.store();  // write back to server
                }
                else highScore = myInfo.getScore();
            }
            draw();
        }
    }
    
    public void draw()
    {
        setImage(new GreenfootImage("HighScore : "+highScore,24,Color.WHITE,Color.BLACK));
    }
}
Dimak Dimak

2018/1/14

#
Umm, the game still crashes whenever I press new game in the menu, Maybe something is wrong with checking if storage is available because that is what appears to crash it. Otherwise if you want to see it for your self the link is on my profile Edit: Crashes in Incognito mode / not logged in Edit 2: Everything else works fine, but adding HighScore to the world crashes it, so I am certain that is the problem
Dimak Dimak

2018/1/14

#
Here is a snippet of code used in the ScoreBoard class that comes with greenfoot.
private void drawUserPanel(int left, int top, int right, int bottom, List users)
    {
               
        UserInfo me = UserInfo.getMyInfo();
        for (Object obj : users)
        {
            UserInfo playerData = (UserInfo)obj;            
            
            if (me != null && playerData.getUserName().equals(me.getUserName()))
            {
                // Highlight our row in a sky blue colour:
                c = BACKGROUND_HIGHLIGHT_COLOR;
            }
            else
            {
                c = BACKGROUND_COLOR;
            }
            
        }
    }
I am interested in the line 9 where UserInfo me is being checked for being null, but that does not seem to work either. As it crashes since I access User Info
danpost danpost

2018/1/14

#
When it crashes, you should be getting some terminal output. What shows there?
There are more replies on the next page.
1
2
3