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

Report as inappropriate.

programmer22
programmer22 presents ...

2011/12/30

YUM!

Controls left arrow key and right (pretty simple) try to eat as many worms as you can

3685 views / 13 in the last 7 days

Tags: game

Your browser does not support the canvas tag.
Dalle4Dalle4

2011/12/30

How do you make the scoreboard??
Dalle4Dalle4

2011/12/30

How do you make the scoreboard??
programmer22programmer22

2011/12/30

well there isnt a score board but there is a counter
Dalle4Dalle4

2011/12/30

ok, but will you tell me how you made it, or a link, something pleas
programmer22programmer22

2011/12/30

hmmm well its a secret =P ........ just kidding ill post the code here for u 2 see import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) import java.awt.Font; /** * Counter that displays a number. * * @author Michael Kolling * @version 1.0.1 */ public class Counter extends Actor { private int value = 0; private int target = 0; private String text; private int stringLength; public Counter() { this(""); } public Counter(String prefix) { text = prefix; stringLength = (text.length() + 2) * 16; setImage(new GreenfootImage(stringLength, 24)); GreenfootImage image = getImage(); Font font = image.getFont(); image.setFont(font.deriveFont(24.0F)); // use larger font updateImage(); } public void act() { if(value < target) { value++; updateImage(); } else if(value > target) { value--; updateImage(); } } public void add(int score) { target += score; } public void subtract(int score) { target -= score; } public int getValue() { return value; } /** * Make the image */ private void updateImage() { GreenfootImage image = getImage(); image.clear(); image.drawString(text + value, 1, 18); } }
programmer22programmer22

2011/12/30

hmmm well its a secret =P ........ just kidding ill post the code here for u 2 see import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) import java.awt.Font; /** * Counter that displays a number. * * @author Michael Kolling * @version 1.0.1 */ public class Counter extends Actor { private int value = 0; private int target = 0; private String text; private int stringLength; public Counter() { this(""); } public Counter(String prefix) { text = prefix; stringLength = (text.length() + 2) * 16; setImage(new GreenfootImage(stringLength, 24)); GreenfootImage image = getImage(); Font font = image.getFont(); image.setFont(font.deriveFont(24.0F)); // use larger font updateImage(); } public void act() { if(value < target) { value++; updateImage(); } else if(value > target) { value--; updateImage(); } } public void add(int score) { target += score; } public void subtract(int score) { target -= score; } public int getValue() { return value; } /** * Make the image */ private void updateImage() { GreenfootImage image = getImage(); image.clear(); image.drawString(text + value, 1, 18); } }
Dalle4Dalle4

2011/12/30

Thanks I try it
Dalle4Dalle4

2011/12/30

ohh it doesn't work :(
b321234b321234

2011/12/31

@Dalle, it doesn't work because you also need to create a new Scoreboard (or counter) object in the world class. It should be like Scoreboard s = new Scoreboard(java.lang.String) Something like that. The code posted here is from the balloon popping game, which is one of the scenarios that come with the greenfoot software. You can find scoreboard and counter there, go check it out ;)
Dalle4Dalle4

2011/12/31

Ok, i will try it

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.