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

2018/4/18

Making a scoreboard

Green_for_Fun Green_for_Fun

2018/4/18

#
I apologies but it has been a lot of years since I did any programming and even longer since Java. I am trying to figure out the easiest way to make a scoreboard that displays the top 10 highest scores with 3 letters that the user inputs. That being said, I am unsure as to whether the easiest way being to make the scoreboard in the actor class or the world class. I currently have my addScore method in my World and there are multiple levels to the game.
danpost danpost

2018/4/19

#
Green_for_Fun wrote...
I am trying to figure out the easiest way to make a scoreboard that displays the top 10 highest scores with 3 letters that the user inputs. That being said, I am unsure as to whether the easiest way being to make the scoreboard in the actor class or the world class. I currently have my addScore method in my World and there are multiple levels to the game.
It took me a second to understand the phrase "with 3 letters that the user inputs", but I finally got it. The addScore method cannot be in the World class, so I must presume you only have one subclass of World that all levels run in. One thing that is left up in the air is whether each level runs in the same World object or in different World objects of the same type. Another thing that must be presumed is that the addScore method adds to the list of high scores and not to the current game score. Showing your World subclass would go a long way to getting a decent answer to whether the scoreboard should be a World or Actor object.
Green_for_Fun Green_for_Fun

2018/4/30

#
This code is in my CrazyWorld class. [Disallowed URL]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public void addScore(int fishType)
    {
        score = score + scores[fishType];
        checkFeesh();
        showScore();
    }
 
    public void checkFeesh()
    {       
        if(getObjects(Fish01.class).isEmpty() && getObjects(Fish02.class).isEmpty() && getObjects(Fish03.class).isEmpty() && getObjects(Boss.class).isEmpty())
        {
           showWinMessage();
        }
    }
I have put my scoreboard as a world class and made it so that when you lose you go to the scoreboard. I'm pretty sure I need an array to check your score against the current 10 high scores, I'm just not sure how I would write something like that.
danpost danpost

2018/4/30

#
Okay, so my presumption about the addScore method was incorrect. Although you have shown it and the method that takes you to what I presume to be the scoreboard, not enough code was given to clarify what might be needed. Best is to show the entire codes for both World subclasses (CrazyWorld and the world showWinMessage method takes you to).
Green_for_Fun Green_for_Fun

2018/4/30

#
This is the entire code for my CrazyWorld world. The only other world I have is my ScoreBoard world.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
import greenfoot.*;
public class CrazyWorld  extends World
{
    private int score;
    private int time;
    private int a;
    private int b;
    private int c;
    private int[] scores = new int[5];
    private int Peli = 1;
    Peli peli = new Peli(this);
    private int timeBonus;
    private int level;
    private int delay = 15;
    private int enemyNum = 1;
    private int bossNum = 1;
 
    /**
     * Constructor for objects of class CrazyWorld.
     *
     */
    public CrazyWorld()
    {    
        super(1100, 600, 1);
        score = 0;          //score starts at 0 and goes up according to the type of fish eaten
        makeLevel();
    }
     
    /**
     * Constructs the level
     */
    public void makeLevel()
    {
        showText("", 550, 150);
        showText("", 550, 170);
        showText("", 550, 190);
        showText("", 550, 210);
        level++; //increases the level by 1.
        showText("Level: " + level, 550, 25);
        removeObjects(getObjects(Actor.class));
        a = Greenfoot.getRandomNumber(6) + 1;
        b = Greenfoot.getRandomNumber(4) + 1;
        c = Greenfoot.getRandomNumber(3) + 1;
        time = 500;         // time starts at 500 and goes down
        showScore();        //displays the score
        showTime();         //displays the time
        addObject (peli, 550, 300);   //adds 1 pelican at the given x,y corridinates
        addEnemy(enemyNum);
        randomFish01(a);  //adds a random number of fish01 to random locations
        randomFish02(b);  //adds a random number of fish02 to random locations
        randomFish03(c);  //adds a random number of fish03 to random locations
        scores[1] = 5;   //gives you 5 points for every fish01 eaten
        scores[2] = 10// gives you 10 points for every fish02 eaten
        scores[3] = 15// gives you 15 points for every fish03 eaten
        scores[4] = 100// gives you 100 points for each boss you kill
        bossMode();
    }
         
    public void act()
    {
        countTime();
        randomHook();
        checkFeesh();
    }
     
    /**
     * Adds randomly falling hooks.
     */
    public void randomHook()
    {
        if (level % 3 != 0)
        {
            if (delay > 0)
            delay--;
            else
            {
                addObject(new Hook(this), Greenfoot.getRandomNumber(1100), 0);
                delay = 15;
            }
             
        }
    }
     
    /**
     * Adds an enemy and makes sure that it will not land on
     * and immediatly kill Peli.
     */
             
    public void addEnemy(int number)
    {
        for(int i=0; i<number; i++)
        {
            Enemy enemy = new Enemy(this);
            int x = 550;
            int y = 300;
            while(x > 450 && x < 650)
            {
                x = Greenfoot.getRandomNumber(getWidth());
            }
            while(y > 200 && y < 400)
            {
                y = Greenfoot.getRandomNumber(getHeight());
            }
            addObject(enemy, x, y);
        }
    }
             
    /**
     * Place a number of Fish01 into the world at random places.
     * The number of Fish01 can be specified.
     */
    public void randomFish01(int howMany)
    {
        for (int i=0; i<howMany; i++)
        {
            Fish01 fish01 = new Fish01();
            int x = Greenfoot.getRandomNumber(getWidth());
            int y = Greenfoot.getRandomNumber(getHeight());
            addObject(fish01, x, y);
        }
    }
     
     
    /**
     * Place a number of Fish02 into the world at random places.
     * The number of Fish02 can be specified.
     */
    public void randomFish02(int howMany)
    {
        for (int i=0; i<howMany; i++)
        {
            Fish02 fish02 = new Fish02();
            int x = Greenfoot.getRandomNumber(getWidth());
            int y = Greenfoot.getRandomNumber(getHeight());
            addObject(fish02, x, y);
        }
    }
     
     
    /**
     * Place a number of Fish03 into the world at random places.
     * The number of Fish03 can be specified.
     */
    public void randomFish03(int howMany)
    {
        for (int i=0; i<howMany; i++)
        {
            Fish03 fish03 = new Fish03();
            int x = Greenfoot.getRandomNumber(getWidth());
            int y = Greenfoot.getRandomNumber(getHeight());
            addObject(fish03, x, y);
        }
    }
     
    /**
     * Makes bossMode every 3 levels
     */
     
    public void bossMode()
    {
        if(level % 3 == 0)
        {
            showText("", 550, 150);
            showText("", 550, 170);
            showText("", 550, 190);
            showText("", 550, 210);
            removeObjects(getObjects(Actor.class));
            addObject (peli, 550, 300);
            for (int i = 0; i<bossNum; i++)
            {
                Boss boss = new Boss(this);
                int x = 550;
                int y = 300;
                while(x > 450 && x < 650)
                {
                    x = Greenfoot.getRandomNumber(getWidth());
                }
                while(y > 200 && y < 400)
                {
                    y = Greenfoot.getRandomNumber(getHeight());
                }
                addObject(boss, x, y);
            }
            enemyNum++;
            bossNum++;
        }
    }       
     
    /**
     * Adds the score given to each fishType.
     * Once all the fish are gone, game stops and the WinMessage
     * and score are shown.
     */
    public void addScore(int fishType)
    {
        score = score + scores[fishType];
        checkFeesh();
        showScore();
    }
     
    public void checkFeesh()
    {       
        if(getObjects(Fish01.class).isEmpty() && getObjects(Fish02.class).isEmpty() && getObjects(Fish03.class).isEmpty() && getObjects(Boss.class).isEmpty())
        {
           showWinMessage();
        }
    }
     
    private void showScore()
    {
        showText("Score:" + score, 80, 25);
    }
     
    /**
     * Decreases the time from the starting 500.
     * If the time reaches 0 before all the fish are eaten,
     * the EndMessage is displayed and the game stops.
     */
    private void countTime()
    {
        time--;
        showTime();
        timeBonus = time * level;
        if (time == 0)
        {
            showEndMessage();
            Greenfoot.stop();
        }
    }
     
    private void showTime()
    {
        showText("Time: " + time, 1000, 25);
    }
     
    /**
     * Allows the Enemy to eat Peli.
     * If the Enemy eats Peli before Peli eats all the fish,
     * The LoseMessage displays and the game stops.
     */
    public void eatPeli()
    {
        Peli = Peli-1;
    }
     
    public void eatenPeli()
    {
        if (Peli == 0)
        {
            showLoseMessage();
            Greenfoot.stop();
        }
    }
     
    /**
     * Displays the messages.
     */
    public void showEndMessage()
    {
        showText("Time is up LOSER!!!!", 550, 150);
        showText("Your final score: " + score + "points", 550, 170);
        Greenfoot.delay(20);
        Greenfoot.setWorld(new Scoreboard());
    }
     
    public void showWinMessage()
    {
        showText("YOU WIN!!!", 550, 150);
        showText("Score - " + score + "points", 550, 170);
        showText("Time bonus - " + timeBonus + "points", 550, 190);
        showText("Total - " + (timeBonus + score) + "points", 550, 210);
        Greenfoot.playSound("music.wav");
        score = score + timeBonus;
        Greenfoot.delay(20);
        makeLevel();
    }
     
    public void showLoseMessage()
    {
        showText("YOU LOSE!!!", 550, 300);
        Greenfoot.delay(20);
        Greenfoot.setWorld(new Scoreboard());
    }
}
This is all I have for my Scoreboard world right now.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import greenfoot.*;
public class Scoreboard extends World
{
     
    private int 1;
    private int 2;
    private int 3;
    private int 4;
    private int 5;
    private int 6;
    private int 7;
    private int 8;
    private int 9;
    private int 10;
    private int yourScore = score;
     
    /**
     * Constructor for objects of class Scoreboard.
     *
     */
     
    public Scoreboard()
    {   
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1100, 600, 1);
        showText("Scoreboard", 550, 25);
        showText("1. ", 75, 75);
        showText("2. ", 75, 125);
        showText("3. ", 75, 175);
        showText("4. ", 75, 225);
        showText("5. ", 75, 275);
        showText("6. ", 75, 325);
        showText("7. ", 75, 375);
        showText("8. ", 75, 425);
        showText("9. ", 75, 475);
        showText("10. ", 75, 525);
}
danpost danpost

2018/4/30

#
Obviously, you just threw this class together without any real intent on having it work (probably just to show anything here). There is no way it could possibly compile and it does not give any indication as to where the scores are coming from. Also, it indicates that the scores will only be retained for the current game session. That is, each time you load the game, you will start with an empty "list" of scores -- not sure that is what you intend.
Green_for_Fun Green_for_Fun

2018/5/10

#
Well, aside from my scoreboard, everything else does work. Hinting at why I am trying to figure out how to make a scoreboard. I am not sure how to make a scoreboard in the sense that I am wanting. I did not just throw the scoreboard class together, I just honestly don't know where to go. I know that each score needs to be an integer but I'm not sure where to go from there.
danpost danpost

2018/5/10

#
Green_for_Fun wrote...
I did not just throw the scoreboard class together, I just honestly don't know where to go.
Well, if I was mistaken -- I apologize. However, intentions still unknown. Also, what specifically do you want to tackle about it first?
You need to login to post a reply.