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

2020/5/4

How do I display the score?

1
2
3
4
Ahmed780 Ahmed780

2020/5/6

#
I tried using apple class but it didnt work."Apple result = new Score();" this line has an error. public EndScreenWorld(double vscore) { super("", 800, 600, new Point2D(0.0, 0.0), 10); gameMusic = new GreenfootSound("endMenu.wav"); Apple result = new Score(); addObject(result, 400, 320); result.setImage( new GreenfootImage("You finished with a score of " + (int)vscore + ".", 40, Color.WHITE, Color.BLACK, Color.YELLOW)); Score feedback = new Score(); addObject(feedback, 400, 380); if (vscore >= 25 && vscore <= 75) { String ranking = new String("intermediate player"); feedback.setImage( new GreenfootImage("You are a " + ranking + ".", 40, Color.BLUE, Color.BLACK, Color.YELLOW)); } if (vscore < 25) { String ranking = new String("novice player"); feedback.setImage( new GreenfootImage("You are a " + ranking + ".", 40, Color.BLUE, Color.BLACK, Color.YELLOW)); } if (vscore > 75) { String ranking = new String(); feedback.setImage( new GreenfootImage("You are a " + ranking + ".", 40, Color.BLUE, Color.BLACK, Color.YELLOW)); } }
danpost danpost

2020/5/6

#
You are still creating a "new Score" object.
Ahmed780 Ahmed780

2020/5/6

#
If I write this "Apple result = new Apple();/Score(), it says cannot find method Score(). How do I fix this error?
danpost danpost

2020/5/6

#
Ahmed780 wrote...
If I write this "Apple result = new Apple();/Score(), it says cannot find method Score(). How do I fix this error?
I really do not think you should use an Apple object either. But, it would be this, if you did:
Apple result = new Apple();
Ahmed780 Ahmed780

2020/5/6

#
It still doesnt work,It says apple cannnot be applied to given type.
danpost danpost

2020/5/6

#
Ahmed780 wrote...
It still doesnt work,It says apple cannnot be applied to given type.
Show code in question.
Ahmed780 Ahmed780

2020/5/6

#
public EndScreenWorld(double score) { super("", 800, 600, new Point2D(0.0, 0.0), 10); gameMusic = new GreenfootSound("endMenu.wav"); Apple result = new Apple(); addObject(result, 400, 320); result.setImage( new GreenfootImage("You finished with a score of " + score + ".", 40, Color.WHITE, Color.BLACK, Color.YELLOW)); Score feedback = new Score(); addObject(feedback, 400, 380);
danpost danpost

2020/5/6

#
What code is in Apple class?
Ahmed780 Ahmed780

2020/5/6

#
import lang.stride.*; import greenfoot.*; /** * */ public class Apple extends SimulationActor { /* (World, Actor, GreenfootImage, Greenfoot and MouseInfo)*/ public int appleColor = 0; /** * */ public Apple(int v_appleColor) { setRotation(Greenfoot.getRandomNumber(720)); if (v_appleColor == 1) { setImage("greenApple.png"); appleColor = 1; } else if (v_appleColor == 2) { setImage("yellowApple.png"); appleColor = 2; } if (v_appleColor == 3) { setImage("greenApple.png"); appleColor = 3; } } /** * */ public void act() { super.act(); if (getY() > 630) { position.setY(position.getY() + 300.0); } } }
danpost danpost

2020/5/6

#
I do not think you want to use an Apple object to display the final score either (apples are animated). Try something else or create a new Actor subclass for it.
Ahmed780 Ahmed780

2020/5/6

#
Isn't it possible to display the score from Score object?
danpost danpost

2020/5/6

#
Ahmed780 wrote...
Isn't it possible to display the score from Score object?
No -- because its image is updated in the act method. That is why it kept showing "0".
Ahmed780 Ahmed780

2020/5/6

#
So I need to create a new subclass like Score to display the score?
danpost danpost

2020/5/6

#
Ahmed780 wrote...
So I need to create a new subclass like Score to display the score?
Not like Score. Just something simple. Like:
import greenfoot..*;

public class SimpleActor extends Actor
{
}
or, equivalently:
public class SimpleActor extends greenfoot.Actor {}
Ahmed780 Ahmed780

2020/5/7

#
Is this correct? public EndScreenWorld(double vscore) { super("", 800, 600, new Point2D(0.0, 0.0), 10); gameMusic = new GreenfootSound("endMenu.wav"); SimpleActor result = new SimpleActor(); addObject(result, 400, 320); result.setImage( new GreenfootImage("You finished with a score of " + (int)vscore + ".", 40, Color.WHITE, Color.BLACK, Color.YELLOW));
There are more replies on the next page.
1
2
3
4