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

2017/3/17

how to create a scoreboard

1
2
fxrrxr fxrrxr

2017/3/17

#
hello how do i create a scoreboard??
Super_Hippo Super_Hippo

2017/3/17

#
You can import the ScoreBoard class (Edit → Import class).
fxrrxr fxrrxr

2017/3/17

#
will this scoreboard be able to tally how many objects is removed every time the program is run? because thats how we determine the score. sorry, im v new and idk abt that class yet
Super_Hippo Super_Hippo

2017/3/17

#
The scoreboard is there to display scores reached by different players. To count it, you only need an int variable or if you want it to be displayed, use the Counter class.
fxrrxr fxrrxr

2017/3/17

#
im sorry im really confused can u please give me an example code? im very new here
danpost danpost

2017/3/17

#
fxrrxr wrote...
im sorry im really confused can u please give me an example code? im very new here
You can use the ScoreBoard class greenfoot provides as an example. The only difference will be that instead of 5 top and 5 near scores, you will be displaying the 10 top scores only. Personally, I think you should work with storing the high scores first -- you will need that for testing the scoreboard.
Super_Hippo Super_Hippo

2017/3/17

#
1
2
3
4
5
6
7
8
private int killCount = 0;
 
//in act
if (isTouching(ClassToRemove.class))
{
    removeTouching(ClassToRemove.class);
    killCount++;
}
danpost danpost

2017/3/17

#
My apologies. Please ignore my last post (crossed issues and users).
fxrrxr fxrrxr

2017/3/17

#
sorry but ill be placing this code in the actor class right?
danpost danpost

2017/3/17

#
fxrrxr wrote...
sorry but ill be placing this code in the actor class right?
That is the only place the code Hippo supplied will work (using 'isTouching' and 'removeTouching').
fxrrxr fxrrxr

2017/3/17

#
i tried placing it in the actor class however its telling me that its illegal. what do i do?
danpost danpost

2017/3/17

#
fxrrxr wrote...
i tried placing it in the actor class however its telling me that its illegal. what do i do?
Show how you incorporated it into your code.
Hello! Me and fxrrxr are doing similar projects so here is my code which is sort of similar to hers
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
public class A extends Actor
{
public A()
    { //this is to resize the image
        GreenfootImage image = getImage();
        image.scale(330, 150);
    }
         public void act()
{
        setLocation (getX(), getY()+6);
private int killCount = 0;
  
//in act
if (isTouching(ClassToRemove.class))
{
    removeTouching(ClassToRemove.class);
    killCount++;
}
        if (Greenfoot.isKeyDown("a"))
        {
           getWorld().removeObject(this); // removing A actor on 'a' press
           Greenfoot.playSound("poppy.wav");// playing 'pop' when A actor is removed
        }
 else if(getY() == getWorld().getHeight()-1)
{
    ((bg)getWorld()).gameOver();
    return;
}
}
}
danpost danpost

2017/3/17

#
Cut line 11 and paste (insert) it at line 3.
WIll line 3 look like this?
1
public A(); private int killCount = 0;
There are more replies on the next page.
1
2