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

2020/4/30

Asteroids ScoreBoard Reading 100

1
2
Sharp1122 Sharp1122

2020/5/1

#
import greenfoot.*; /** * Write a description of class Counter here. * * @author (your name) * @version (a version number or a date) */ public class Counter extends Actor { private int value = 0; private String text; /** * Create a counter without a text prefix, initialized to zero. */ public Counter() { this(""); } /** * Create a counter with a given text prefix, initialized to zero. */ public Counter(String prefix) { text = prefix; int imageWidth= (text.length() + 2) * 10; setImage(new GreenfootImage(imageWidth, 16)); updateImage(); } /** * Increment the counter value by one. */ public void increment() { value++; updateImage(); } /** * Show the current text and count on this actor's image. */ private void updateImage() { GreenfootImage image = getImage(); image.clear(); image.drawString(text + value, 1, 12); } public int getValue() { return value; } } Is the get method getValue?
Sharp1122 Sharp1122

2020/5/1

#
If I use your code,"addObject(new ScoreBoard(scoreCounter.getScore())," and add scoreCounter.getValue()). the getValue works but the getScore doesn't.
Yehuda Yehuda

2020/5/1

#
Yes, the getter method is "getValue." The code would be:
addObject(new ScoreBoard(scoreCounter.getValue()), getWidth() / 2, getHeight() / 2);
Sharp1122 Sharp1122

2020/5/1

#
This goes below the public void gameOver?
Yehuda Yehuda

2020/5/1

#
Yes. I took your line of code, and replaced the "100" for "scoreCounter.getValue()". I just wanted to get a chance to use the code tags so that you can see them and follow.
Sharp1122 Sharp1122

2020/5/1

#
That worked! Thank you so much!
You need to login to post a reply.
1
2